how can I import a database by running just one command?
我尝试学习如何将数据库导入PostgreSQL。
我的尝试失败了,我使用
1 2 3 4 5 6 7 8 | $ sudo -u postgres pg_restore -C -d postgres dvdrental.tar pg_restore: [archiver (db)] Error while PROCESSING TOC: pg_restore: [archiver (db)] Error FROM TOC entry 2194; 1262 17355 DATABASE pagila postgres pg_restore: [archiver (db)] could NOT EXECUTE query: ERROR: invalid locale name:"English_United States.1252" Command was: CREATE DATABASE pagila WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'English_United States.1252' LC_CTYPE = 'English_United States.1252'; pg_restore: [archiver (db)] could NOT EXECUTE query: ERROR: DATABASE"pagila" does NOT exist Command was: ALTER DATABASE pagila OWNER TO postgres; pg_restore: [archiver (db)] could NOT reconnect TO DATABASE: FATAL: DATABASE"pagila" does NOT exist |
我的问题是:
-
我想知道为什么我的第一次尝试失败了?
-
有没有办法只运行一个命令?
该文件说:
-C
--createCreate the database before restoring into it. If --clean is also specified, drop and recreate the target database before
connecting to it.
甚至提供一个例子:
Assume we have dumped a database called mydb into a custom-format
dump file:
1 $ pg_dump -Fc mydb > db.dumpTo drop the database and recreate it from the dump:
1
2 $ dropdb mydb
$ pg_restore -C -d postgres db.dumpThe database named in the -d switch can be any database existing in
the cluster; pg_restore only uses it to issue the CREATE DATABASE
command for mydb . With -C , data is always restored into the
database name that appears in the dump file.
谢谢。
更新:
再次感谢。 我发现转储中的二进制文件
1 | CREATE DATABASE pagila WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'English_United States.1252' LC_CTYPE = 'English_United States.1252';` |
是否可以修改它以使
请注意,我有一个有效的解决方案:
在
1 2 3 4 5 | template1=# CREATE DATABASE dvdrental; CREATE DATABASE $ sudo -u postgres pg_restore -d dvdrental dvdrental.tar $ |
导入失败,因为您尝试导入转储的操作系统不知道区域设置
除了要存在语言环境之外,无法使