Password file for the PostgreSQL client command

Source: Internet
Author: User
Tags chmod postgresql psql postgresql client

Password file for the PostgreSQL client command:

Before giving other PostgreSQL client commands, we need to introduce the password file in PostgreSQL. This document is described in advance here because we will apply the file extensively in the following sample code to ensure that our scripts are automated. In other words, if the file is not provided when the client command executes, all of the client commands for PostgreSQL are interrupted by the password input prompt.

In the current user's home directory, we need to manually create a password file named. pgpass, so that when we connect to the PostgreSQL server, the client commands automatically read the file to obtain the password information required to log in. The format of the file is as follows:

Hostname:port:database:username:password

The above data is a colon as a delimiter, a total of five fields, respectively, the server hostname (IP), the server listening port number, login access to the database name, login user name and password, the first four fields can use an asterisk (*) to indicate matching any value. See the example below:

/> Cat > Pgpass

*:5432:postgres:postgres:123456

Ctrl+d

The #.pgpass file must have permissions of 0600 to prevent any global or group users from accessing it, otherwise this file will be ignored.

/> chmod 0600. Pgpass

Before we learn the client commands behind, we need to create the file manually based on our own application environment so that all subsequent sample code will use the password file, so that they can be done automatically in batch mode.

[email protected] ~]$ cat. Pgpass

127.0.0.1:3685:testdb2:testwjw:123456

[Email protected] ~]$ chmod 0600. Pgpass

[Email protected] ~]$ egrep "TESTDB2|TESTWJW"/data/postgresql/data/pg_hba.conf

Host TESTDB2 TESTWJW 127.0.0.1/32 MD5


[Email protected] ~]$ pg_ctl reload-d/data/postgresql/data-l/data/postgresql/log/postgres.log

Server signaled


[[email protected] ~]$ psql-utestwjw-d testdb2-h 127.0.0.1-p 3685 (so login is not required password)

Psql.bin (9.5.9)

Type ' help ' for help.


Testdb2=>


Once commented out. pgpass the contents of this file

[email protected] ~]$ cat. Pgpass

# #127.0.0.1:3685:testdb2:testwjw:123456

[Email protected] ~]$ pg_ctl reload-d/data/postgresql/data-l/data/postgresql/log/postgres.log

Server signaled


[Email protected] ~]$ psql-utestwjw-d testdb2-h 127.0.0.1-p 36985

Password for user testwjw: # # # #此处提示要输入密码123456

Psql.bin (9.5.9)

Type ' help ' for help.

Testdb2=>

This article is from the "10931853" blog, please be sure to keep this source http://wujianwei.blog.51cto.com/10931853/1970731

Password file for the PostgreSQL client command

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.