PostgreSQL : Install2018/06/25 |
Install PostgreSQL to configure database server.
|
|
[1] | Install and start PostgreSQL. |
root@dlp:~#
apt -y install postgresql
root@dlp:~#
vi /etc/postgresql/10/main/postgresql.conf # line 59: uncomment and change if you allow accesses from remote hosts listen_addresses = ' * '
systemctl restart postgresql |
[2] | Set PostgreSQL admin user's password and add a user and also add a test database. |
# set password root@dlp:~# su - postgres postgres@dlp:~$ psql -c "alter user postgres with password 'password'" ALTER ROLE # add DB user [ubuntu] as an example postgres@dlp:~$ createuser ubuntu
# create a test database (owner is the user above) postgres@dlp:~$ createdb testdb -O ubuntu
|
[3] | Login as a user just added above and operate DataBase as test operation. |
# show Databases ubuntu@dlp:~$ psql -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 testdb | ubuntu | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (4 rows) # connect to test DB ubuntu@dlp:~$ psql testdb
psql (10.4 (Ubuntu 10.4-0ubuntu0.18.04))
Type "help" for help. # set password testdb=# alter user ubuntu with password 'password'; ALTER ROLE # create a test table testdb=# create table test ( no int,name text ); CREATE TABLE # insert test data testdb=# insert into test (no,name) values (1,'ubuntu'); INSERT 0 1 # show tables testdb=# select * from test;
no | name ----+-------- 1 | ubuntu (1 row) # delete test table testdb=# drop table test; DROP TABLE # quit testdb=# \q
# delete test database ubuntu@dlp:~$ dropdb testdb
|
Sponsored Link |