如何在全新安装后login并validationPostgresql?

在mint ubuntu上安装了新的postgres 8.4。 如何为postgres创build用户并使用psqllogin?

当我键入psql时,它只是告诉我

psql: FATAL: Ident authentication failed for user "my-ubuntu-username" 

有两种方法可以使用。 两者都需要创build一个用户一个数据库。

  1. 使用createuser和createdb

     $ sudo -u postgres createuser -s $USER $ createdb mydatabase $ psql -d mydatabase 
  2. 使用SQLpipe理命令,并通过TCP连接密码

     $ sudo -u postgres psql postgres 

    然后,在psql shell中

     CREATE ROLE myuser LOGIN PASSWORD 'mypass'; CREATE DATABASE mydatabase WITH OWNER = myuser; 

    然后你可以login,

     $ psql -h localhost -d mydatabase -U myuser -p <port> 

    如果你不知道这个端口,你可以通过运行以下命令来获得它,作为postgres用户,

     SHOW port; 

    要么,

     $ grep "port =" /etc/postgresql/*/main/postgresql.conf 

旁注: postgres用户

我build议不要修改postgres用户。

  1. 它通常是从操作系统locking的。 没有人应该作为postgres “login”到操作系统。 你应该有root权限来authenticationpostgres
  2. 它通常不受密码保护,并委托给主机操作系统。 这是一件好事 。 这通常意味着要以PostgreSQL作为SQL Server的SA的PostgreSQL等价物login,您必须具有对基础数据文件的写入访问权限。 而且,这意味着无论如何你都可以正常地破坏。
  3. 通过保持禁用状态,可以消除通过指定的超级用户进行暴力攻击的风险。 隐藏和遮蔽超级用户的名字具有优势。

默认情况下你需要使用postgres用户:

 sudo -u postgres psql postgres 

你得到的错误是因为你的Ubuntu的用户名不是一个有效的Postgres用户。

你需要告诉psql使用哪个数据库用户名

 psql -U postgres 

您可能还需要指定要连接到的数据库

 psql -U postgres -d <dbname> 

如果您的数据库客户端使用TCP / IP连接,并且在pg_hba.conf中configuration了ident auth,请检查是否已安装并运行identd。 即使只有本地客户端连接到“本地主机”,这也是强制的。

另外请注意,如今identd可能必须为Postgresql 启用IPv6才能欢迎连接到本地主机的客户端。

你也可以连接到数据库作为“普通”用户(而不是postgres):

 postgres=# \connect opensim Opensim_Tester localhost; Password for user Opensim_Tester: You are now connected to database "opensim" as user "Opensim_Tester" on host "localhost" at port "5432"