我用
pg_dump db_production > postgres_db.dump
然后使用scp将其复制到localhost。
现在当我导入我的本地db时,它给出了一个错误
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.
使用命令行
pg_restore -d db_development postgres_db.dump
我用
pg_dump db_production > postgres_db.dump
然后使用scp将其复制到localhost。
现在当我导入我的本地db时,它给出了一个错误
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.
使用命令行
pg_restore -d db_development postgres_db.dump
当前回答
上面的答案对我没用,下面这个有用:
PSQL db_development < postgres_db.dump
其他回答
提供了一个简单的回答,这对我有用,对你也适用于大多数情况
psql -U username -d database_name < dump_file.sql . d
如果上面给出与角色相关的错误,则将username替换为postgres。
psql -U postgres -d database_name < dump_file.sql . d
如果你有一个完整的数据库转储:
PGPASSWORD="your_pass" psql -h "your_host" -U "your_user" -d "your_database" -f backup.sql
但是,如果您的模式是分开保存的,那么这就行不通了。然后需要禁用数据插入触发器,类似于pg_restore——disable-triggers。然后你可以使用这个:
cat database_data_only.gzip | gunzip | PGPASSWORD="your_pass" psql -h "your_host" -U root "your_database" -c 'SET session_replication_role = replica;' -f /dev/stdin
另一方面,我认为这是postgres的一个非常不幸的缺点。在pg_dump中创建转储的默认方式与pg_restore不兼容。然而,加上一些额外的关键字,它就是。WTF ?
psql -U <username> -d <database-name> -h <host-name> -f <backup.sql> . p
上面的答案对我没用,下面这个有用:
PSQL db_development < postgres_db.dump
对我来说,就像这样。
C:\Program Files\PostgreSQL\12\bin> psql -U postgres -p 5432 -d dummy -f C:\Users\Downloads\d2cm_test.sql