PostgreSQL Database Pg_dump command line method of not entering a password

Source: Internet
Author: User
Tags psql

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:

Hostname:port:database:username:password

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

which

-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:

\l

To exit the database console:

\q

Tag:postgresql database backup, PostgreSQL command line does not enter a password, PostgreSQL database basic operations, PostgreSQL database export, PostgreSQL operation and Maintenance tutorial

--end--

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.