archlinux use postgresql

First, the preparatory operations

After the default installation has been created postgres system user

Switch User

$ sudo -iu postgres # Or su - postgres for root

Initialization data directory

[postgres]$ initdb --locale=zh_CN.UTF-8 -E UTF8 -D /var/lib/postgres/data

Exit this user, start the service postgresql.service

 

Second, common operations

Enter sudo -iu postgres again,

Add a new database user

$ createuser --interactive

Create a database

$ createdb myDatabaseName

  

Login psql shell

-d myDatabaseName psql 
# View all databases 
\ L 
# switch databases 
\ c <Database> 
# list all users and permissions 
\ du 
# lists all the tables in the current database 
\ dt

 

Third, the configuration file

Set up remote access

/var/lib/postgres/data/postgresql.conf
listen_addresses = 'localhost,my_local_ip_address'

 

Fourth, troubleshooting and other

View Log

journalctl -u postgresql.service

 

Modify the template UTF-8

First, we need to drop template1. Templates cannot be dropped, so we first modify it so it is an ordinary database:

UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
DROP DATABASE template1;

The next step is to create a new database from template0, with a new default encoding.modify template1 so it is actually a template:

UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';

Now you can create a new database:

[postgres]$ createdb blog


233

Guess you like

Origin www.cnblogs.com/lemos/p/11605557.html