//
you're reading...
Database, IT-Center

Postgres Database

Backup SQL Format using PgAdmin:
1. Right click in database
2. Set Format to “Plain”

Restore SQL Format (Plain) in Windows
1. cmd
2. type : psql -h host -U user -p port dbname < file (User use U capslock)

example : C:\Program Files\PostgreSQL\9.3\bin>psql -h localhost -U postgres -p 5443 fantasi < c:/fantasy_server.backup

Restore SQL Format (Plain) in Unix
1. Login using postgres user : su – postgres
2. restore database

psql -h localhost -U postgres -p 5432 eticket_v2 < /var/www/html/eticket_v2/db/filedb_bank_20160618.backup

Backup & Restore Large Database in Unix
Open putty/terminal type this for backup :

root$ su - postgres
bash$ pg_dump -U $username $dbname > /var/www/html/$file

and using query for restore :

root$ su - postgres
bash$ pg_restore -U $username $dbname < /var/www/html/$file

 

Connecting Postgres with PHP

Setting Apache from httpd.conf and adding line script like this:

LoadFile "C:/Program Files/PostgreSQL/8.4/bin/libpq.dll"
Setting PHP from php.ini and open ext module php_pgsql, and try this :
<?php
$dbconn = pg_connect("dbname=mary");
//connect to a database named "mary"

$dbconn2 = pg_connect("host=localhost port=5432 dbname=mary");
// connect to a database named "mary" on "localhost" at port "5432"

$dbconn3 = pg_connect("host=sheep port=5432 dbname=mary user=lamb password=foo");
//connect to a database named "mary" on the host "sheep" with a username and password

$conn_string = "host=sheep port=5432 dbname=test user=lamb password=bar";
$dbconn4 = pg_connect($conn_string);
//connect to a database named "test" on the host "sheep" with a username and password

$dbconn5 = pg_connect("host=localhost options='--client_encoding=UTF8'");
//connect to a database on "localhost" and set the command line parameter which tells the encoding is in UTF-8
?>

Forced Rename Postgres Database

-- disconnect from the database to be renamed
\c postgres

-- force disconnect all other clients from the database to be renamed
SELECT pg_terminate_backend( procpid )
FROM pg_stat_activity
WHERE procpid <> pg_backend_pid( )
    AND datname = 'name of database';

-- rename the database (it should now have zero clients)
ALTER DATABASE "name of database" RENAME TO "new name of database";

About berbagisolusi

Berbagi merupakan sebuah bentuk simbol keikhlasan untuk membantu dan menolong, sedangkan solusi adalah cara menyelesaikan masalah. Setiap manusia pasti mengalami masalah, tetapi kita tidak perlu mengalami masalah yang sama jika orang lain pernah mengalami dan kita tahu hal tersebut.

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

April 2014
M T W T F S S
« Oct   Jun »
 123456
78910111213
14151617181920
21222324252627
282930  

Archives

Web Statistic

Blog Stats

  • 149,580 hits
%d bloggers like this: