将 Windows 上的 .sql 文件导入到 postgresql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3204274/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 06:48:45  来源:igfitidea点击:

Importing .sql file on windows to postgresql

sqlwindowspostgresqlimport

提问by David

I have a .sql file that was created by postgresql a while back. I now want to import this file onto a windows machine running postgresql.

我有一个由 postgresql 创建的 .sql 文件。我现在想将此文件导入到运行 postgresql 的 Windows 机器上。

How do I do this. The file is about 1.5gb.

我该怎么做呢。该文件大约为 1.5GB。

回答by pcent

You should use psqlcommand line tool:

您应该使用psql命令行工具:

psql -h hostname -p port_number -U username -f your_file.sql databasename 

回答by AmaChefe

click on the SQL Shell and log into the database and use import

单击 SQL Shell 并登录到数据库并使用导入

Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Password for user postgres:
psql (9.2.4)
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
Type "help" for help.

postgres=# \i c:/data/data01.sql

回答by Tom

This also works for me:

这也适用于我:

psql dbname username < file.sql

回答by Lucas Gervas

start you psql command tool, it will give you dialog like the following

启动你的 psql 命令工具,它会给你如下对话框

Server [localhost]:
Database [postgres]:
Port [5432]:yourport
Username [postgres]:
Password for user postgres:**********

then connect to your database

然后连接到你的数据库

postgres=# \c yourdatabase;

then import the file

然后导入文件

yourdatabase=# \i c:/path/path/data/data01.sql

note the / for directory separator & no spaces in file path

注意 / 用于目录分隔符 & 文件路径中没有空格

回答by Ipsita Upadhyay

command prompt

命令提示符

open your cmd windowand type the following (make sure the path of postgres is correct)

打开你的cmd窗口并输入以下内容(确保postgres的路径正确)

."C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -h 127.0.0.1 -p 5432 -U postgres -d dbname <./query.sql

."C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -h 127.0.0.1 -p 5432 -U postgres -d dbname <./query.sql