If you’re not happy with the default locale (collation order, number formatting, translated messages) you can re-create the database cluster using another locale.
(You can override the locale for a specific database upon creation.)
12345
service postgresql stop
cd /var/lib/postgresql/9.1
rm -rf main
mkdir main
chown -R postgres:postgres main
12
su - postgres
initdb --locale=sv_SE.UTF-8 -A md5 -W -D main
When you re-create the main database cluster you also have to generate new certificates:
pg_controldata main | grep LC
LC_COLLATE: sv_SE.UTF-8
LC_CTYPE: sv_SE.UTF-8
Securing postgres User Account
Changing the postgres operating system password:
1
passwd postgres
Changing the postgres database password:
123
su - postgres
psql
\password
Configuring access to the PostgreSQL Server
Make sure postgres user can login using operating system account. All other database users must login using md5 password.
/etc/postgresql/9.1/main/pg_hba.conf
12
local all postgres ident
local all all md5
Password-less login
The file .pgpass in a user’s home directory can contain passwords to be used if the connection requires a password (and no password has been specified otherwise).
This file should contain lines of the following format:
~/.pgpass
1
hostname:port:database:username:password
Each of the first four fields can be a literal value, or *, which matches anything.
1
chmod 0600 ~/.pgpass
PostgreSQL Server Applications
Frequently used server applications:
123
initdb # create a new PostgreSQL database clusterpg_controldata # display control information of a PostgreSQL database clusterpg_ctl # start, stop, or restart a PostgreSQL server
PostgreSQL Client Applications
All client applications will by default connect with the database user name that is equal to the current operating system user name. Specify the -U option to override this.
Frequently used client applications:
12345678910
createdb # create a new PostgreSQL databasecreateuser # define a new PostgreSQL user accountdropdb # remove a PostgreSQL databasedropuser # remove a PostgreSQL user accountpg_config # retrieve information about the installed version of PostgreSQLpg_dump # extract a PostgreSQL database into a script file or other archive filepg_restore # restore a PostgreSQL database from an archive file created by pg_dumppsql # PostgreSQL interactive terminalreindexdb # reindex a PostgreSQL databasevacuumdb # garbage-collect and analyze a PostgreSQL database
psql examples
psql is a terminal-based front-end to PostgreSQL.
1
psql -U username
Frequently used psql commands:
1234567
\c[dbname]# connect to new database\d# list tables, views, and sequences\d name # describe table, view, sequence, or index\dt [pattern]# list tables\du [pattern]# list roles (users)\l# list all databases\password [username]# securely change the password for a user
You can also execute SQL queries:
1
SELECT*FROMusers;
Common tasks
Examples in psql, SQL and client application as appropriate.