5

Can we create a database on remote machine in postgresql DB, if yes then how?

7
  • If you have the needed permissions AND the postgres server itself is installed/running on that machine then yes... please elaborate with details...what have you tried ? what is not working ? Commented Nov 16, 2011 at 7:26
  • I am writing a script that i will run fom my local machine. Commented Nov 16, 2011 at 7:30
  • that doesn't say much... what kind of script ? what is installed/running on the remote machine ?... Commented Nov 16, 2011 at 7:32
  • I am writing a script that i will run fom my local machine. This script copy the db from local machine and upload in the remote machine but i want to create the db from my local machine to remote machine. Commented Nov 16, 2011 at 7:33
  • that didn't answer my questions... sorry this way I don't see how I could help... Commented Nov 16, 2011 at 7:34

2 Answers 2

2

Yes. Assuming the remote server is Linux, and assuming you have sudo or root privileges on that server, you could SSH into the remote server and use a package manager (like yum, synaptic, or apt) to install the PostgreSQL server.

You can configure it using vi (or emacs or other text editor). Usually, the files you edit are found in the /var/lib/pgsql/data folder, and an /etc/init.d/postgresql startup script for whenever the server reboots. You'll usually need to edit the pg_hba.conf file to allow a connection from your client's subnet. That part can be troublesome if overlooked.

You'll be able to initially run psql as the postgres user, and can create datatabases, run scripts, etc from the command line. Once you allow a remote connection, you can do the same from the comfort of your own gui, such as PgAdminIII or any Java-based database manager that can use a JDBC connector.

Example:

psql -U postgres
create database foo;
\q
Sign up to request clarification or add additional context in comments.

2 Comments

I want a command that create empty database from local machine to remote machine
If you're seeking to COPY a database from one PostgreSQL server to another, you would perform a pg_dump of the source database to generate a SQL script, and use psql to execute that script on the target database.
0

First, get your programming language. Let say it's PHP to make it simple.

Second, you get the PostGresql connector. Here is the link for PHP but you can get for all popular language.

Third, you open a connection and you do the command you want. You want to create a database so you call the create database YourDatabaseName command.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.