在mint ubuntu上重新安装了postgres 8.4.如何创建postgres用户并使用psql登录?
当我输入psql时,它只会告诉我
psql: FATAL: Ident authentication failed for user "my-ubuntu-username"
在mint ubuntu上重新安装了postgres 8.4.如何创建postgres用户并使用psql登录?
当我输入psql时,它只会告诉我
psql: FATAL: Ident authentication failed for user "my-ubuntu-username"
有两种方法可以使用.两者都需要在数据库中创建一个用户and.
默认情况下,psql连接到与用户同名的数据库.因此,有一个惯例将其定为"user's database".如果用户只需要一个数据库,就没有理由打破这种惯例.我们将使用mydatabase
作为示例数据库名称.
Using createuser and createdb,我们可以明确数据库名称,
$ sudo -u postgres createuser -s $USER
$ createdb mydatabase
$ psql -d mydatabase
您可能应该完全忽略这一点,让所有命令都默认为用户名.
$ sudo -u postgres createuser -s $USER
$ createdb
$ psql
Using the SQL administration commands, and connecting with a password over TCP
$ sudo -u postgres psql postgres
然后在psqlshell 中
CREATE ROLE myuser LOGIN PASSWORD 'mypass';
CREATE DATABASE mydatabase WITH OWNER = myuser;
然后你可以登录,
$ psql -h localhost -d mydatabase -U myuser -p <port>
如果您不知道端口,您可以通过运行以下命令来获得它,作为postgres
用户,
SHOW port;
或
$ grep "port =" /etc/postgresql/*/main/postgresql.conf
postgres
user我建议NOT修改postgres
用户.
postgres
的身份"登录"操作系统.你应该有root才能认证为postgres
.postgres
(相当于SQL Server SA
的PostgreSQL)身份登录,您必须具有对底层数据文件的写访问权限.而且,这意味着,你通常可以 destruct 浩劫无论如何.