English 中文(简体)
1. 建立邮政数据库,使用批量文档,包括[雇员]、[登记]、[所有人]和(或)文件。
原标题:Create Postgres database using batch file with [template],[encoding],[owner] and a .sql file

我想利用批量文档建立一个邮政数据库。 现在,这样做的正常方法是:

“C:Program filesPostgreSQL9.0increatedb.exe”——U Myadmin Mydat AbseName

以上这一文字创建了一个数据库,其中包含违约数据库参数。 然而,我希望建立一个数据库,其参数如下:

   WITH OWNER = Myadmin 
   TEMPLATE = template0 
   ENCODING =  SQL_ASCII 
   TABLESPACE = pg_default
   LC_COLLATE =  C 
   LC_CTYPE =  C 
   CONNECTION LIMIT = -1;

Please tell me how to create a database with the above parameters using Batch files.

让我也知道,如何像这一指挥线一样,使用 file子:

"C:Program FilesPostgreSQL9.0increatedb.exe" -U Myadmin -f C:createDB.sql;
最佳回答

The client program createdb does not support all those options.
Create a file db_create.sql:

CREATE DATABASE MydatAbseName
   WITH OWNER myadmin 
   TEMPLATE template0
   ENCODING  SQL_ASCII 
   TABLESPACE  pg_default
   LC_COLLATE   C 
   LC_CTYPE   C 
   CONNECTION LIMIT  -1;

呼吁:

psql -U postgres postgres -f C:/path/to/db_create.sql

The trick here is to connect to the default maintenance db "postgres" and create the new database from there. I do it with the default superuser named "postgres" in my example.
psql -f executes the SQL commands in the given file.

您也只能执行一个带有<条码>-c的单一指挥系统。 (无相关档案):

psql -U postgres postgres -c "CREATE DATABASE MydatAbseName WITH OWNER Myadmin
EMPLATE template ENCODING  SQL_ASCII  TABLESPACE  pg_default LC_COLLATE   C 
LC_CTYPE  C  CONNECTION LIMIT  -1"

More on creating a database in the fine manual here and here.
More on psql.


On Windows, it looks something like this:

"C:Program FilesPostgreSQLverson_numberinpsql.exe" -U user -f C:/path/to/db_create.sql postgres

The last "postgres" is the name of the default maintenance db. If you want to use it in a batch file you have to answer a password prompt or connect with a user that is allowed access without providing a password. Basics in chapters The Password File and The pg_hba.conf File of the manual. More here:

问题回答

暂无回答




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签