Showing posts with label postgres. Show all posts
Showing posts with label postgres. Show all posts

Thursday, May 17, 2012

My note of postgresql

oracle sysdate => now()

trunc(sysdate) => date_trunc('day', now());

rownum

SELECT 
    row_number() OVER () AS i, 
    e.col1, 
    e.col2, 
    ... FROM ... 



select ... from .. LIMIT 100;

sequence_name.nextval() => nextval('sequence_name')



java -jar /path/to/schemaSpy_5.0.0.jar -t pgsql -host MYHOSTNAME -db DBNAME -s SCHEMANAME -u USERNAME -p PASSWORD -o /path/to/output/directory -dp /path/to/postgresql-9.1-902.jdbc3.jar -charset utf-8


import
=====
copy {table_name}
from '/path/to/file.csv'
DELIMITER ',' CSV;



thanks
 http://stackoverflow.com/questions/3959692/rownum-in-postgresql

Wednesday, May 9, 2012

Cannot Connect PostgreSQL Remotely

could not connect to server: Connection refused Is the server running on host "......" (......) and accepting TCP/IP connections on port ....?

Solution
========
sudo vi /etc/postgresql/8.4/main/postgresql.conf

listen_addresses = '*'
port = 5432



After changing this file, you need to restart the server process to make the setting effective.

sudo service postgresql start



Note from pgadmin3
===================
For security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first.

For PostgreSQL servers starting with version 8.0, this is controlled using the "listen_addresses" parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use '*' to listen on all available IP addresses.


Other Related Info
===================
sudo vi /etc/postgresql/8.4/main/pg_hba.conf

to allow connections from any remote address.
host all all 0.0.0.0/0 md5

psql -U {username} -h {hostname} -D {database_name}


thanks http://kb.mediatemple.net/questions/1237/How+do+I+enable+remote+access+to+my+PostgreSQL+server%3F#dv

Wednesday, February 8, 2012

Postgresql File System Level Backup Debian

In order to perform postgresql backup on debain, there are some modification on
http://www.postgresql.org/docs/9.1/interactive/backup-file.html


sudo service apache2 stop
sudo service postgresql stop

#%y%m%d_%H-%M
sudo tar -cvpjf /a/path/postgres-`date +%y%m%d`.tar.bz2 -C /var/lib/postgresql/9.1/main .

# Prevent parent directories from being tarred
#   -C, --directory DIR
#           change to directory DIR

# -p, --preserve-permissions, --same-permissions
#           extract information about file permissions (default for superuser)


sudo service postgresql start
sudo service apache2 start

# when extract
#sudo tar -xvjf postgres-xxxxxx.tar.bz2

Monday, November 14, 2011

postgres createdb invalid locale name debian

$ sudo -u postgres createdb -l th_TH.UTF-8 -E UTF-8 -T template0 mydb;
createdb: database creation failed: ERROR:  invalid locale name th_TH.UTF-8

$ locale -a
C
en_US.utf8
POSIX

$ sudo apt-get install locales

$ sudo dpkg-reconfigure locales
# in debian this command will display a screen while ubuntu not!!

$ sudo init 6

$ locale -a
C
en_US.utf8
POSIX
th_TH.utf8



Useful cmd
=======
$ sudo locale-gen th_TH.UTF-8
$ sudo locale-gen --purge en_US.UTF-8 th_TH.utf8


$ sudo apt-get install locales-all