我使用这两个命令从旧服务器创建了一个备份:
pg_dump -d DBNAME > backup.sql
pg_dump -F t DBNAME > backup.tar
现在我将它转移到新服务器并尝试恢复它:
postgres@server:~$ psql -U USERNAME -d DBNAME < backup.sql
psql: FATAL: Peer authentication failed for user "USERNAME"
postgres@server:~$ pg_restore -U USERNAME -d DBNAME < backup.tar
pg_restore: [archiver (db)] connection to database "DBNAME" failed: FATAL: Peer authentication failed for user "USERNAME"
我也运行了这些查询:
create database DBNAME;
create user USERNAME;
GRANT ALL PRIVILEGES ON DATABASE DBNAME TO USERNAME;
ALTER USER USERNAME WITH PASSWORD 'MyPassWord';
ALTER USER USERNAME WITH SUPERUSER createdb createrole replication bypassrls;
但我仍然得到上述错误。
我也修改了
/etc/postgresql/10/main/pg_hba.conf
为:
local all all peer # change this to md5
来源
psql -V
:
psql (PostgreSQL) 10.23 (Ubuntu 10.23-0ubuntu0.18.04.1)
目的地
psql -V
:
psql (PostgreSQL) 10.23 (Ubuntu 10.23-0ubuntu0.18.04.1)
我最后想要的是用用户名和密码认证恢复。