Importing .sql file on windows to postgresql

前端 未结 7 1632
春和景丽
春和景丽 2020-12-25 12:23

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.

How do I do this. The file

相关标签:
7条回答
  • 2020-12-25 12:58

    command prompt

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

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

    0 讨论(0)
  • 2020-12-25 13:00

    This also works for me:

    psql dbname username < file.sql
    
    0 讨论(0)
  • 2020-12-25 13:06

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

    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

    0 讨论(0)
  • 2020-12-25 13:10

    If you're doing it with a URI connection string make sure the arguments are before the URI, Powershell examples:

    Works on windows:

    .\psql -f TestFile.sql $connString
    
    .\psql -c 'SELECT Version();' $connString
    

    Won't work on windows (URI connection before arguments):

    .\psql $connString -c 'SELECT Version();' 
    
    0 讨论(0)
  • 2020-12-25 13:18

    You should use psql command line tool:

    psql -h hostname -p port_number -U username -f your_file.sql databasename 
    
    0 讨论(0)
  • psql -U <dbusername>
    if the prompt makes you enter password, do that.
    \c <yourdatabasename>
    \i 'thepathusing/delimiter.sql'
    

    Two points you need to watch out that

    • Use / as writing path of the file instead of \.
    • Use single quote symbol ' instead of ".
    0 讨论(0)
提交回复
热议问题