问题描述
我的电脑发生故障,但幸运的是我备份了
文件夹C:\Program Files\PostgreSQL。
现在我正在工作新的计算机,我想导入存储在外部磁盘中的以前的
Postgres数据库。
我想导出特定数据库的模式
位于备份文件夹中。
文件 PostgreSQL\8.3\data\global\pg_database
包含关于数据库及其OID的信息
;例如:
db120012
db223456
我想导出db1的模式。
有一个名为20012在文件夹PostgreSQL\8.3\data\base\20012
包含大量文件[500文件] p>
有没有办法导出该数据库的模式?
请注意,所有Postgresql数据库文件都位于
在外部硬盘,我想导出该数据库的模式在一个SQL文件中,采取该文件,运行它并在本地创建相同的确切数据库。
可以这样做吗?
解决方案你应该看看 pg_dump
pg_dump -s databasename
只将模式转储为stdout as .sql。
对于Windows,您可能需要调用 pg_dump.exe
。我没有访问Windows机器,但我非常确定从内存的命令。看看帮助是否适用于您。
My computer broke down but fortunately I backed upthe folder C:\Program Files\PostgreSQL.
Now I'm working in a new computer and I would like to import the previousPostgres databases that are stored in the external disk.
I would like to export the schema of a specific databasethat is located in the backup folder.
The file PostgreSQL\8.3\data\global\pg_database
contains informationabout databases and their OIDs; for example:
"db1" 20012
"db2" 23456
I would like to export the schema of "db1".
There is a folder named "20012" in folder "PostgreSQL\8.3\data\base\20012"
that contains a lot of files [500 files].
Is there any way to export the schema of that database?
Note that all of the Postgresql database files are locatedin an external hard disk and I would like to export the schema of that database in an SQL file, take that file, run it and create the same exact database locally.
Can this be done?
解决方案 You should take a look at pg_dump
:
pg_dump -s databasename
Will dump only the schema to stdout as .sql.
For windows, you'll probably want to call pg_dump.exe
. I don't have access to a Windows machine but I'm pretty sure from memory that's the command. See if the help works for you too.
这篇关于如何在PostgreSQL中导出数据库的模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!