Postgres database on Linux import and restore backup data

 

How to restore database in Postgresql database in Linux? What about executing sql script files? Specific steps are as follows:

First, restore the database backup file

1. Copy the database backup file xxx.backup to / opt with a connection tool, this is not fixed, and the location is free to place;

2. Open the terminal in linux and switch to the postgres user, the command is

 su-postgres (user created when creating postgresql database),

Then cd to the bin directory of the postgresql you installed, my installation is under / opt, the command is

 cd /opt/postgres/9.3/bin

Enter the command after opening

 ./psql

Enter your database password to enter the postgres database;

3. Create your database first, command

create database xxx;

4. Then restore the database backup file for the xxx database, the command is

 ./pg_restore -U postgres -W -d xxx (your database) -v "/opt/xxx.backup" (your backup file location)

 

备份:pg_dump -h localhost -p 5432 -U tradesns -W -F c -b -v -f "/home/tradeworkwangbin/us2010.backup" us2010
恢复:pg_restore -h 127.0.0.1 -p 5432 -U postgres -W -d zjyj_gxversion -v "/opt/zjyj_gxversion_0410.backup"

 

5, x database to perform database backup recovery on linux command message does not have permission to ask questions user "postgres" password authentication failure. (password authentication failed for user & quot; postgres & quot;) modification:

 

 Solution:

   Modify the pg_hba.conf configuration file

Change the indent of the configuration file to trust

 

Second, execute the sql script file in postgres

1. Open the terminal in linux, switch to the postgres user, and then cd to the bin directory of the postgresql you installed (same as above),

  cd /opt/postgres/9.3/bin

2. Copy your xxx.sql file to / opt /, and then execute the command as follows

   ./psql -s xxx (xxx is the database you want to execute) -f /opt/xxx.sql

 

Three, popular science

1. Database backup, the command is as follows:

  ./pg_dump -h localhost -p 5432 -U postgres -W -F c -b -v -f "/opt/xxx.backup" xxx

2. In the database installation directory bin, ./psql to enter the database, enter the password, \ c xxx (database name) to enter the specified database

\ i file path

 

 

Guess you like

Origin www.cnblogs.com/ComputerVip/p/12679517.html