在debian 11上新安装postgresql 13

发布时间 2023-06-01 13:32:42作者: huorexiaji

1、安装

sudo apt install postgresql-all

2、建立用户

sudo su - postgres,可以免密登录数据库
create user myuser with password '111' CREATEDB;
用新用户登录,不出意外应该会报Peer authentication failed for user XXX,原因是因为/etc/postgresql/13/main/pg_hba.conf中的local all all pear,将pear改成md5,重启服务就行了。
然后会报另一个问题,database "xxx" does not exist,xxx跟用户名一致。原因是因为psql登录时,如果不指定数据库名字,会默认使用跟用户名一样的数据库,显然目前这个数据库不存在,
所以可以指定登录template1数据库,psql -U user -d template1,登录进去之后create database user,下次就能用默认数据库登录了