Chinaunix首页 | 论坛 | 博客
  • 博客访问: 333212
  • 博文数量: 81
  • 博客积分: 3813
  • 博客等级: 中校
  • 技术积分: 945
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-24 18:14
文章分类

全部博文(81)

文章存档

2013年(1)

2012年(2)

2011年(54)

2010年(15)

2009年(9)

分类: Mysql/postgreSQL

2011-02-10 15:08:37

These instructions assume you are using PostgreSQL from the Redhat RPMS. On other systems, the location of the configuration files and the name of the administrative user may be different.

As root, become the postgres user.

  1. # su - postgres
  2. -bash-3.00$

Open up /var/lib/pgsql/data/pg_hba.conf in your text editor and look for the authentication method for the postgres user. Unless you are connecting to PostgreSQL over the network, it will be a local user, so look for the line starting with that:

  1. local all postgres md5

Network users would begin with "host" and there would also be an IP address and netmask:

  1. host all postgres 10.255.255.10 255.255.255.0 md5

If your system is configured for all users to authenticate in the same way, you see "all" in place of a username.

  1. local all all md5

Note that "md5" may be set to "password" or a number of other options, but you want to make it "ident sameuser". This means you can connect to PostgreSQL as long as you are the user specified.

  1. local all postgres ident sameuser

After you have saved your changes to pg_hba.conf, issue the command 'pg_ctl reload'. You will be able to connect now with psql.

  1. -bash-3.00$ pg_ctl reload postmaster signaled 
  2. -bash-3.00$ psql 
  3. Welcome to psql 8.1.8, the PostgreSQL interactive terminal. 

  4. Type: \copyright for distribution terms 
  5.       \h for help with SQL commands 
  6.       \? for help with psql commands 
  7.       \g or terminate with semicolon to execute query 
  8.       \q to quit 

  9. postgres=#

Now reset your password.

  1. postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD 'password'; 
  2. ALTER ROLE 
  3. postgres=# \q

Now re-edit pg_hba.conf to set it back to using md5 or password authentication (md5 is more secure). Signal a reload again, then run psql to make sure it is working.

  1. -bash-3.00$ pg_ctl reload 
  2. postmaster signaled
  3. -bash-3.00$ psql 
  4. Password:
  5. Welcome to psql 8.1.8, the PostgreSQL interactive terminal. 

  6. Type: \copyright for distribution terms 
  7.       \h for help with SQL commands 
  8.       \? for help with psql commands 
  9.       \g or terminate with semicolon to execute query 
  10.       \q to quit 

  11. postgres=#
阅读(660) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~