PostgreSQL pg_dump command line Without Password

Source: Internet
Author: User
Tags psql
For PostgreSQL database backup, one of the methods described in the official manual is ldquo and SQLDumprdquo. (another method is to directly back up the files in the file system.

For PostgreSQL database backup, one of the methods described in the official manual is ldquo; SQL Dumprdquo; (another method is to directly back up the files in the file system

For PostgreSQL database backup, one of the methods in the official manual is to adopt the "SQL Dump" method (another method 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 shown in the command line, pg_dump outputs the command results to the standard output.

Second, pg_dump does not affect other operations in the database operation process (mainly concerned about whether pg_dump will generate read/write locks (read lock and write lock), but there are also exceptions, that is, the operations that require exclusive lock, such as alter table.

For O & M, you usually need to use scripts to perform database backup instead of manually execute command lines and enter the password for backup every day. Therefore, I checked the document according to "31.15. the Password File section describes how to create a configuration File in The user directory and write The Password to The configuration File in advance. The format of The configuration File is as follows:

Hostname: port: database: username: password

Put the file in the user directory that executes the pg_dump command, save it as a. pgpass file, and the permission is 600. Otherwise, PostgreSQL will report

WARNING: password file "/root/. pgpass" has group or world access; permissions shocould be u = rw (0600) or less

Note: If the database schema of the PostgreSQL database depends on OIDs (for example, foreign keys), The-o option must be added to pg_dump.

The export speed of the PostgreSQL database is still relatively fast. The export speed of more than 30 thousand rows is less than 1 s.

PostgreSQL exports database command line instances:

Pg_dump-U confluence-d confluence-h>/tmp/tmp_confluence_postgresql. SQL


-Utable indicates the execution user

-D indicates the database

-H indicates the host

-O indicates that OLDs is supported.

Note: If you do not want to use the. pgpass file, you can add the-W option in the command line, which means entering the password and then executing it.

Appendix: basic operations suitable for O & M of PostgreSQL databases

Log on to the PostgreSQL database:

Psql-U dbuser-d exampledb-h 5432

If you do not want to enter the password, run the following command:

Psql "host = hostaddr = port = 5432 user = yourloginname password = yoursecret"

List databases:

\ L

Log out of the Database console:

\ Q

Tag: PostgreSQL database backup, PostgreSQL command line without entering password, basic PostgreSQL database operations, PostgreSQL database export, PostgreSQL O & M tutorial

-- End --

------------------------------------ Lili split line ------------------------------------

Install PostgreSQL 6.3 on yum in CentOS 9.3

PostgreSQL cache details

Compiling PostgreSQL on Windows

Configuration and installation of LAPP (Linux + Apache + PostgreSQL + PHP) Environment in Ubuntu

Install and configure phppgAdmin on Ubuntu

Install PostgreSQL9.3 on CentOS

Configure a Streaming Replication cluster in PostgreSQL

How to install PostgreSQL 7/6 and phpPgAdmin in CentOS 5/6. 4

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