PostgreSQL Veritabanı Yönetimi ve Kullanımı
PostgreSQL, yüksek performans, genişletilebilirlik ve güvenilirlik özelliklerine sahip güçlü, açık kaynaklı bir ilişkisel veritabanı yönetim sistemidir. ServBay, PostgreSQL ile birlikte gelir ve bu makalede, ServBay'de PostgreSQL veritabanını yönetme ve kullanma yöntemlerinin detayları, kurulum, yapılandırma, yedekleme, geri yükleme ve performans optimizasyonu dahil olmak üzere açıklanmaktadır.
PostgreSQL'in Kurulumu ve Yapılandırılması
ServBay, PostgreSQL ile birlikte gelir. Servisler
paneli üzerinden farklı versiyonların kurulumu, değişimi ve yönetimi yapılabilir.
PostgreSQL Servisinin Başlatılması ve Yönetimi
PostgreSQL servisini ServBay'in yönetim platformu veya komut satırı aracı servbayctl
üzerinden yönetebilirsiniz.
ServBay Yönetim Platformunu Kullanma
- ServBay Yönetim Platformunu Açın.
- “Servisler” sekmesine gidin.
- PostgreSQL servisini bulun ve başlatma, durdurma veya yeniden başlatma işlemlerini gerçekleştirin.
servbayctl
Komut Satırı Aracını Kullanma
# PostgreSQL servisini başlatma
servbayctl start postgresql 16
# PostgreSQL servisini durdurma
servbayctl stop postgresql 16
# PostgreSQL servisini yeniden başlatma
servbayctl restart postgresql 16
# PostgreSQL servis durumunu görüntüleme
servbayctl status postgresql 16
2
3
4
5
6
7
8
9
10
11
PostgreSQL'in Yapılandırılması
ServBay'in varsayılan PostgreSQL yapılandırma dosyası optimize edilmiştir. Kullanıcıların yapılandırma dosyasını manuel olarak değiştirmesi gerekirse, postgresql.conf
dosyasını şu konumda bulabilirler:
/Applications/ServBay/db/postgresql/16/postgresql.conf
Farklı PostgreSQL versiyonlarına göre yapılandırma dosyaları farklı klasörlerde bulunur.
PostgreSQL'e Bağlanma
PostgreSQL'e komut satırı aracı psql
veya pgAdmin gibi grafiksel araçları kullanarak bağlanabilirsiniz.
Komut Satırı Üzerinden Bağlanma
TCP/IP Üzerinden Bağlanma:
bashpsql -U your_username -h localhost -d your_database -p 5432
1Socket Üzerinden Bağlanma:
bashpsql -U your_username -h /Applications/ServBay/tmp -d your_database
1
pgAdmin Kullanarak Bağlanma
- pgAdmin'i Açın.
- Yeni bir sunucu bağlantısı oluşturun.
- Bağlantı bilgilerini girin:
- Hostname:
localhost
- Port:
5432
- Username: ServBay yönetim panelinden alınabilir
- Password: ServBay yönetim panelinden alınabilir
- Hostname:
Veritabanı Yönetimi
Veritabanı ve Kullanıcı Oluşturma
Veritabanı Oluşturma:
sqlCREATE DATABASE mydatabase;
1Kullanıcı Oluşturma ve Yetkilendirme:
sqlCREATE USER your_username WITH PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE mydatabase TO your_username;
1
2
Yedekleme ve Geri Yükleme
Veritabanı Yedekleme
Yedek dosyasının aşağıdaki dizinde saklanmasını öneririz:
/Applications/ServBay/backup/postgresql
pg_dump
aracını kullanarak veritabanını yedekleme:
pg_dump -U your_username -d mydatabase -F c -b -v -f /Applications/ServBay/backup/postgresql/mydatabase.dump
Veritabanı Geri Yükleme
pg_restore
aracını kullanarak veritabanını geri yükleme:
pg_restore -U your_username -d mydatabase -v /Applications/ServBay/backup/postgresql/mydatabase.dump
Performans Optimizasyonu
PostgreSQL, çeşitli performans optimizasyon seçenekleri sunar. İşte bazı yaygın yöntemler.
İndeks Optimizasyonu
Sık kullanılan sorguların kolonlarına indeks ekleyin. Örneğin:
CREATE INDEX idx_column_name ON your_table_name(column_name);
Sorgu Optimizasyonu
EXPLAIN
komutunu kullanarak sorgu performansını analiz edin ve uygun optimizasyonları yapın. Örneğin:
EXPLAIN SELECT * FROM your_table_name WHERE column_name = 'value';
Yapılandırma Optimizasyonu
Yapılandırma dosyasındaki parametreleri performansı artırmak için ayarlayın. Örneğin, paylaşılan hafıza boyutunu ayarlayın:
shared_buffers = 1GB
Güvenlik Yönetimi
Veritabanı güvenliğini sağlamak çok önemlidir, işte bazı güvenlik yönetim önerileri.
Güçlü Şifre Ayarlama
Tüm veritabanı kullanıcıları için güçlü şifreler ayarlayın:
ALTER USER your_username WITH PASSWORD 'your_new_password';
Düzenli Yedekleme
Düzenli olarak veritabanı yedekleri alarak veri kaybını önleyin.
Erişimi Sınırlama
Veritabanı kullanıcılarının erişim yetkilerini sınırlayın ve sadece gerekli yetkileri verin:
REVOKE ALL PRIVILEGES ON DATABASE mydatabase FROM your_username;
GRANT CONNECT, TEMPORARY ON DATABASE mydatabase TO your_username;
2
Sık Karşılaşılan Sorunlar ve Çözümleri
PostgreSQL'e Bağlanamama
PostgreSQL'in çalışıp çalışmadığını kontrol edin:
bashservbayctl status postgresql 16
1Güvenlik duvarı ayarlarını kontrol edin: PostgreSQL'in portunun (varsayılan 5432) güvenlik duvarından geçişine izin verildiğinden emin olun.
Yetki Sorunları
Kullanıcı yetkilerini kontrol edin:
sql\du
1Gerekli yetkileri verin:
sqlGRANT ALL PRIVILEGES ON DATABASE mydatabase TO your_username;
1
Sonuç
PostgreSQL, güçlü ve esnek bir veritabanı yönetim sistemidir. ServBay ile birlikte kullanıldığında, veritabanı yönetimi ve kullanımı daha da kolay hale gelir. Bu makalede sunulan bilgilerle, PostgreSQL'in kurulumunu, yapılandırılmasını, bağlantısını, yönetimini, yedekleme ve geri yükleme işlemlerini ve performans optimizasyonu yöntemlerini kolayca gerçekleştirebilir, veritabanının verimli çalışmasını ve güvenliğini sağlayabilirsiniz.