Bir serverdan yangi serverga postgresql database ni ko’chirish.
- ko’chirmoqchi bo’lgan data bor serverga ga kirib ushbu buyruqni kiritamiz:
pg_dump -U username -h localhost database_name > backup.sql
undan keyin bizdan postgres password so’raydi shundan so’ng bu buyruq databse dagi ma’lumotni backup.sql file ga yuklaydi.
2. endi backup.sql file ni ko’chirmoqchi bo’lgan serverga yuboramiz.
scp backup.sql user@123.45.67.89:/path/to/destination/
bu buyruqdan keyin bizdan serverning passwordini so’raydi passwordni kiritganimizdan keyin esa backup.sql file yangi serverdagi biz bergan destinationga yuboriladi.
3. yangi serverga kiramiz va postgresql ga kirib database create qilib olamiz.
4. biz yuqoridan bergan destinationga kirib olamiz va ushbu buyruqni yuboramiz:
psql -U your_user_name -d your_database_name < backup.sql
bu buyruqdan keyin bizdan postgresql password so’raydi passwordni kiritgandan keyin esa database ga backup.sql file dagi datalar joylashtirib chiqiladi.
va barchasi tayyor.
⚠️ Agar 4 — qadamdagi buyruqdan keyin ushbu error chiqsa:
psql: error: FATAL: Peer authentication failed for user “postgres”
sudo nano /etc/postgresql/13/main/pg_hba.conf
pg_hba.conf fileda
local all postgres peer
dan
local all postgres md5
ga o’tkazib qo’yamiz.