我知道这是一个奇怪的请求,但由于一些我无法避免的骇人听闻的原因,我希望能够始终如一地将几个表从一个数据库同步到另一个数据库。我知道我可以自己在脚本中写出功能,但我认为pg_dump并将pg_restore对我自己不了解的过程应用很多优化。
我想知道是否有办法pg_restore覆盖现有的表。基本上,在伪代码中是这样的:
-- pseudo code
begin;
drop table to_restore;
drop table to_restore2;
drop table to_restore3;
-- etc
restore table to_restore;
restore table to_restore2;
restore table to_restore3;
-- etc
commit;
Run Code Online (Sandbox Code Playgroud)
如果这不是那么好,我也愿意接受其他方法。
只是试图从资源恢复教程数据库:http : //www.postgresqltutorial.com/load-postgresql-sample-database/
所以,在这段代码之后
pg_restore -U postgres -d dvdrental /Users/fedotarte/Downloads/dvdrental.zip
Run Code Online (Sandbox Code Playgroud)
我收到当前消息:
pg_restore: [archiver] 输入文件似乎不是有效的存档
我应该怎么做才能成功恢复数据库?
先感谢您!
我需要从计算机1中以postgres用户名1转储一个postgres数据库,然后在具有postgres用户名2的computer2上还原它。我一直遇到似乎备份文件要使用username1的错误:
当我在computer2上运行它时:
psql dbname < backupname.pgsql
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
ERROR: role "username1" does not exist
Run Code Online (Sandbox Code Playgroud)
我试过了:
// Dumping from computer1:
pg_dump dbname > backupname.sql
pg_dump dbname > backupname.pgsql
pg_dump -U username1 dbname -N topology -T spacial_ref_sys > backupname.pgsql
// Restoring on computer2:
psql dbname < backupname.pgsql
Run Code Online (Sandbox Code Playgroud)
是否需要修改转储或还原才能克服此问题?
我正在倾倒一个像这样的大型 Postgres 表:
pg_dump -h myserver -U mt_user --table=mytable -Fc -Z 9 --file mytable.dump mydb
Run Code Online (Sandbox Code Playgroud)
以上创建了一个mytable.dump文件。我现在想将此转储恢复到名为mytable_restored.
我怎样才能使用pg_restore命令来做到这一点?
我有一个*.dump文件(postgresql转储),我想输出my_table到my_table.csv.是否有更好的方法来执行此操作pg_restore -t my_table db.dump > my_table.txt,然后编写脚本以从输出创建CSV?
在仅使用模式的 PostgreSQL 中public,在调用其他函数的检查约束函数中使用的表中的数据不会导入pg_restore,在调用其他函数的检查约束函数中使用的表中的数据在使用 转储后pg_dump。但是,如果检查约束中的函数不调用其他函数,则数据会正确导入。
我在从 9.3.22 到 9.3.23 以及从 9.4.16 到 9.4.17 进行小幅升级后注意到了这种行为;在 9.3.22 和 9.4.17 中运行良好。
\n\n我理解是由于search_path 的变化:
\n\n\n\n\n避免在 pg_dump 和其他客户端程序中使用不安全的 search_path 设置 (Noah Misch, Tom Lane)
\n\npg_dump、pg_upgrade、vacuumdb 和其他 PostgreSQL 提供的应用程序本身很容易受到前面变更日志条目中描述的劫持类型的影响;由于这些应用程序通常由超级用户运行,因此它们是特别有吸引力的目标。为了确保它们的安全,无论整个安装是否受到保护,请将它们修改为在其 search_path 设置中仅包含 pg_catalog\n 架构。Autovacuum 工作进程现在也执行相同的操作。
\n\n如果用户提供的函数由这些程序\xe2\x80\x94 间接执行,例如,索引表达式 \xe2\x80\x94 中的用户提供的函数,更严格的 search_path 可能会导致错误,这将\需要通过调整这些用户提供的函数来纠正,以不假设任何有关它们在什么搜索路径下调用的信息。这一直是很好的做法,但现在它对于正确的行为是必要的。(CVE-2018-1058 或 CVE-2018-1058)
\n
我仍然不清楚为什么允许拥有一级公共函数,但这些函数不能调用其他函数。
\n\n例如,具有以下结构和数据:
\n\nCREATE OR REPLACE FUNCTION is_even(n integer) RETURNS boolean AS $BODY$ \nBEGIN\n return n%2 = 0; …Run Code Online (Sandbox Code Playgroud) 我尝试学习如何将数据库导入PostgreSQL。
我的尝试失败了,我使用pg_restore -C ... -d ...一个命令将新数据库的创建和从文件导入到新数据库结合起来:
$ 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: …Run Code Online (Sandbox Code Playgroud) C:\Program Files (x86)\pgAdmin III\1.22\pg_restore.exe --host localhost --port 5432 --username "postgres" --dbname "randd" --role "postgres" --no-password --verbose "C:\Users\ranjeet\Desktop\RandDbackup19-3final.backup"
Run Code Online (Sandbox Code Playgroud)
pg_restore: [archiver] 文件头中不受支持的版本 (1.13)
我在转储和恢复我的一个数据库时遇到了问题,我认为是由于公共模式中的一些扩展所致。引发错误的扩展似乎是Cube扩展或EarthDistance扩展。这是我收到的错误:
pg_restore: [archiver (db)] Error from TOC entry 2983;
pg_restore: [archiver (db)] could not execute query: ERROR: type "earth" does not exist
LINE 1: ...ians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
QUERY: SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
CONTEXT: SQL function "ll_to_earth" during inlining
Command was: REFRESH MATERIALIZED VIEW public.locationsearch
Run Code Online (Sandbox Code Playgroud)
我自己编写的一些函数也遇到了类似的不同问题,问题最终是搜索路径,因此明确地将这些函数的搜索路径设置为公开解决了我的问题。我尝试了同样的方法ll_to_earth,但似乎整个扩展都是问题。我真的不想尝试安装扩展,pg_catalog因为这似乎是不好的做法。
这是我典型的转储命令:
pg_dump -U postgres -h ipAddress -p 5432 -w -F t database > database.tar
其次是:
pg_restore -U postgres -h localhost -p 5432 -w -d postgres -C "database.tar"
-s包含数据的完整转储大约为 4GB,但我尝试仅使用和转储模式-F …
有人可以帮助我使用 SSL 证书恢复 postgres db。我尝试了以下方式,但没有用
pg_restore "host=hostname user=username dbname=database_name sslcert=sslcert.crt sslkey=sslkey.key sslrootcert=sslroot.pem sslmode=verify-full" -f filename
Run Code Online (Sandbox Code Playgroud)
它给出了以下错误
pg_restore: [archiver] could not open input file "host=hostname user=username dbname=database_name sslcert=sslcert.crt sslkey=sslkey.key sslrootcert=sslroot.pem sslmode=verify-full": No such file or directory
Run Code Online (Sandbox Code Playgroud) 我以这种方式创建了 PostgresSQL 数据库的备份:
/usr/bin/pg_dump --no-owner --no-acl > dump.sql
当我尝试在另一台机器上恢复时:
psql db < dump.sql 它引发了许多错误: invalid command \N
当我尝试使用pg_restore:
pg_restore dump.sql -d db
不同的错误: pg_restore: [archiver] input file appears to be a text format dump. Please use psql.
根据文档,这应该不是问题。
有什么方法可以告诉psql\N 字符是空值?
pg-restore ×12
postgresql ×12
pg-dump ×5
database ×4
psql ×2
pg ×1
postgres-9.4 ×1
sql ×1
ssl ×1