postgresql 如何在本地打开 .sql 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7313135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open an .sql file locally?
提问by Vahagn
I have an .sql file which is around 2 gb of size. I want to open the database locally on my laptop.
我有一个大约 2 GB 的 .sql 文件。我想在我的笔记本电脑上本地打开数据库。
To do so I guess I have to install both the SQL server and the SQL client application on my laptop.
为此,我想我必须在笔记本电脑上同时安装 SQL 服务器和 SQL 客户端应用程序。
Can you please direct me to the appropriate installation packages and documentation on how to obtain this all (I will welcome any answer concerning Windows or Linux)?
您能否指导我找到有关如何获得所有这些的适当安装包和文档(我欢迎任何有关 Windows 或 Linux 的答案)?
I am sure the answer is not, but still, can I open the .sql file with MS Access?
我确定答案不是,但我仍然可以使用 MS Access 打开 .sql 文件吗?
Here are the first few lines of the .sql file
这是 .sql 文件的前几行
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET client_encoding = 'SQL_ASCII';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
回答by mal-wan
The 2gb file you've got is a PostgreSQL Dump File (ie a dump of their entire database, schema, data and all).
你得到的 2gb 文件是一个 PostgreSQL 转储文件(即他们整个数据库、模式、数据和所有的转储)。
I'd suggest you install PostgreSQL (note, you could use any database, but since it was dumped from Postgres, we can play it safe and try to restore to the same engine):
我建议你安装 PostgreSQL(注意,你可以使用任何数据库,但由于它是从 Postgres 转储的,我们可以安全地使用它并尝试恢复到同一个引擎):
http://www.postgresql.org/download/windows<- Just download and install the One Click Installer if you're on windows
http://www.postgresql.org/download/windows<- 如果您使用的是 Windows,只需下载并安装一键安装程序
And then you will need to restore that dump file to a database:
然后您需要将该转储文件恢复到数据库:
This page will walk you through it: http://www.postgresql.org/docs/8.1/static/backup.html#BACKUP-DUMP-RESTORE
此页面将引导您完成它:http: //www.postgresql.org/docs/8.1/static/backup.html#BACKUP-DUMP-RESTORE
But it is essentially running the following:
但它本质上正在运行以下内容:
psql db_to_restore_to < yourdump.sql
You'll then have the full database setup ready to be queried (and you can hook up to the PostreSQL database via Access too if you are used to Access or aren't familiar with writing SQL)
然后,您将准备好完整的数据库设置以供查询(如果您习惯使用 Access 或不熟悉编写 SQL,也可以通过 Access 连接到 PostreSQL 数据库)