One way to do a backup of the PostgreSQL database according to the official manual is to use "SQL Dump" (another way is to directly back up files in the file system, refer to the official manual).
The basic usage is as follows:
Pg_dump dbname > outfile
First, as the command line shows, Pg_dump is outputting the command result to the standard output.
Second, Pg_dump does not affect other operations in the database work (mainly concerned about whether Pg_dump will generate read lock, write lock), but there are exceptions, which require the use of mutexes (exclusive lock) operations, such as Alter TABLE.
Since it is often necessary to use scripts to perform database backups for operations, instead of manually executing the command line and entering a password backup every day, you have specifically checked the documentation, according to document "31.15. The description of the Password file section, you can build a profile in the user directory, in advance to write the password to this configuration file, the format of the configuration file is as follows:
This file needs to be placed in the user directory where the pg_dump command is executed, saved as a. pgpass file, and the permission is 600, otherwise PostgreSQL will report
Warning:password file "/root/.pgpass" have group or world access; Permissions should is U=RW (0600) or less
Note: If the database schema of the PostgreSQL database relies on OIDs (for example, a foreign key), the Pg_dump requires the-o option.
PostgreSQL database export speed is still relatively fast, export more than 30,000 lines less than 1s.
PostgreSQL Export Database command-line instance:
Pg_dump-u confluence-d confluence-h 127.0.0.1-o >/tmp/tmp_confluence_postgresql.sql
-U represents the execution user
-D indicates the database
-H indicates that the host
-O indicates support for olds
Note: If you do not want to use a. pgpass file, you can add the-w option to the command line, meaning that you enter the password to execute.
Appendix: PostgreSQL Database Some basic operations for operation and maintenance
Log in to the PostgreSQL database:
Psql-u dbuser-d exampledb-h 127.0.0.1-p 5432
If you do not want to enter a password, you can do it:
Psql "host=127.0.0.1 hostaddr=127.0.0.1 port=5432 user=yourloginname Password=yoursecret"
List the databases:
To exit the database console:
Tag:postgresql database backup, PostgreSQL command line does not enter a password, PostgreSQL database basic operations, PostgreSQL database export, PostgreSQL operation and Maintenance tutorial
This article is from "Communication, My Favorites" blog, please make sure to keep this source http://dgd2010.blog.51cto.com/1539422/1685968
PostgreSQL Database Pg_dump command line method of not entering a password