# su - postgres
Last login: Thu May 14 21:44:54 KST 2020 on pts/6
-bash-4.2$ psql
psql (12.2)
Type "help" for help.

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)


postgres=# create database "blog.daonelab.com";
CREATE DATABASE
postgres=# \l
                                      List of databases
       Name        |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-------------------+----------+----------+-------------+-------------+-----------------------
 blog.daonelab.com | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres          | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0         | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                   |          |          |             |             | postgres=CTc/postgres
 template1         | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                   |          |          |             |             | postgres=CTc/postgres
(4 rows)

postgres-# \c blog.daonelab.com
You are now connected to database "blog.daonelab.com" as user "postgres".

blog.daonelab.com=# create user blog with password '********';
CREATE ROLE
blog.daonelab.com=# alter role blog set client_encoding to 'utf-8';
ALTER ROLE
blog.daonelab.com=# alter role blog set timezone to 'Asia/Seoul';
ALTER ROLE
blog.daonelab.com=# grant all privileges on database "blog.daonelab.com" to blog;
GRANT
blog.daonelab.com=# \l
                                      List of databases
       Name        |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-------------------+----------+----------+-------------+-------------+-----------------------
 blog.daonelab.com | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
                   |          |          |             |             | postgres=CTc/postgres+
                   |          |          |             |             | blog=CTc/postgres
 postgres          | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0         | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                   |          |          |             |             | postgres=CTc/postgres
 template1         | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                   |          |          |             |             | postgres=CTc/postgres
(4 rows)


# psql -h 127.0.0.1 -p 5432 -U blog -d blog.daonelab.com
Password for user blog: 
psql (12.2)
Type "help" for help.

blog.daonelab.com=> 

 

# hostname설정하면 hostname으로도 접속 가능

# vi /etc/hostname
-----------------------------------------------------------------------
linux.daonelab.com


# psql -h linux.daonelab.com -p 5432 -U blog -d blog.daonelab.com
Password for user blog: 
psql (12.2)
Type "help" for help.

blog.daonelab.com=>