[英]How to create an sql dump file of a Postgres database using psql
I currently have created a database via Supabase, which uses the Postgres database.我目前通过 Supabase 创建了一个数据库,它使用 Postgres 数据库。 After doing so, I then downloaded Postgres on my computer, which gave me the psql command line script for use to connect to postgres databases.
这样做之后,我在我的计算机上下载了 Postgres,它为我提供了 psql 命令行脚本,用于连接到 postgres 数据库。
I intend to create a local backup of my Supabase database through the psql script.我打算通过 psql 脚本创建我的 Supbase 数据库的本地备份。 This is after I have connected to the supabase database through psql
这是在我通过 psql 连接到 supbase 数据库之后
From this, i can see that psql successfully connected to the database.从这里,我可以看到 psql 成功连接到数据库。
I then tried to use the pg_dump command to attempt to create a dump file of the database.然后我尝试使用 pg_dump 命令尝试创建数据库的转储文件。 This was the command I used:
这是我使用的命令:
pg_dump postgresql://postgres:[Database password]@db.epvzhrganrzfwexmiksg.supabase.co:5432/postgres > dumpfile.sql pg_dump postgresql://postgres:[数据库密码]@db.epvzhrganrzfwexmiksg.supabase.co:5432/postgres > dumpfile.sql
However, after I pressed enter, psql did not run the command, it simply moved to a new command line.但是,在我按下回车后,psql 并没有运行该命令,它只是移动到了一个新的命令行。 As such, I am not sure whether I inputted something wrong for the dump command or is it a different psql command I need to use for it.
因此,我不确定我是否为转储命令输入了错误的内容,还是我需要使用不同的 psql 命令。
as mentioned by @adrian-klaver the pg_dump command should be run directly from the terminal, and not from inside the psql shell正如@adrian-klaver 所提到的,pg_dump 命令应该直接从终端运行,而不是从 psql shell 内部运行
run pg_dump -V
to check that it's installed.运行
pg_dump -V
以检查它是否已安装。 It is usually installed when you install psql https://stackoverflow.com/a/49689589/1267728它通常在安装 psql 时安装https://stackoverflow.com/a/49689589/1267728
As mentioned, you have successfully connected with psql.如前所述,您已成功连接 psql。
From OS prompt从操作系统提示
$ pg_dump mydb > mydb.sql
From psql prompt从 psql 提示符
postgres# \! pg_dump mydb > mydb.sql
Post backup done , mydb.sql file can be copied & import via psql to local machine.备份完成后,可以通过 psql 将 mydb.sql 文件复制并导入到本地计算机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.