简体   繁体   中英

How to run .sql script in remote linux machine to create database in postgresql?

I have a .sql script for postgresql and want to run it on linux remote machine. I am using postgres 9.4.

In this script i have included database name and the table detail also.

I just want to run this script so that it will create database and tables at the same time.

So, please tell me the command to run this script file on remote machine.

I tried following:-

psql -d myDataBase -a -f myInsertFile

In my case

psql -a -f db_script_ddl.sql

But it is not working.

It is asking for the data base database name. But i do not want to pass any database name. I want script to create and connect to database and then to create tables.

Following is what i have inside the script file to create database and table:-

DROP DATABASE IF EXISTS testDB;

CREATE DATABASE testDB;
\c testDB
Other commands to create tables.

But it is not working.

Help me out.

Please put one example, it will be easy to understand.

Thanks.

psql must connect to a database. There is no option to connect to "no database in particular".

Use the postgres database if you want to drop/create a database and switch to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM