DB/PostgreSQL

CentOS7 PostgreSQL 12 Install

강서버 2020. 9. 9. 23:30
728x90
반응형

# Install the repository RPM:

$ sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm 

 

# Install PostgreSQL:

$ sudo yum install -y postgresql12-server

 

# Optionally initialize the database and enable automatic start:

$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb

$ sudo systemctl enable postgresql-12

$ sudo systemctl start postgresql-12

 

www.postgresql.org/download/linux/redhat/

 

PostgreSQL: Linux downloads (Red Hat family)

Linux downloads (Red Hat family) The Red Hat family of distributions includes: Red Hat Enterprise Linux CentOS Fedora Scientific Linux Oracle Linux and others. PostgreSQL is available on these platforms by default. However, each version of the platform nor

www.postgresql.org

$ systemctl list-unit-files --type=service | grep post*
postfix.service                               enabled 
postgresql-12.service                         enabled 

 

$ systemctl status postgresql-12

 postgresql-12.service - PostgreSQL 12 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; vendor preset: disabled)
   Active: active (running) since 수 2020-09-09 23:30:01 KST; 8min ago

 

0 postgres password change

root change

$ su -

 

- postgres change

# su - postgres

 

-bash-4.2$ psql -c "alter user postgres with password 'PASSWORD'"
ALTER ROLE

 

- postgres exit

-bash-4.2$ exit

 

- root exit

# exit

 

- modify postgresql.conf

$ sudo vi /var/lib/pgsql/12/data/postgresql.conf

--------------------------------------------------------

[ before ]

#listen_addresses = 'localhost'

[ after ]

listen_addresses = '*'

--------------------------------------------------------

 

- add pg_hba.conf

$ sudo vi /var/lib/pgsql/12/data/pg_hba.conf

--------------------------------------------------------

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             0.0.0.0/0               md5

 

- postgresql service restart

$ sudo systemctl restart postgresql-12

 

$ psql -h 192.168.174.128 -U postgres -d postgres

postgres=#

 

postgres=# CREATE DATABASE mydb TEMPLATE template0 LC_COLLATE 'C';

CREATE DATABASE

postgres=# CREATE ROLE myuser WITH LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOREPLICATION CONNECTION LIMIT -1 PASSWORD 'mypasswd';

CREATE ROLE

postgres=# ALTER DATABASE mydb OWNER TO myuser;

ALTER DATABASE

 

- psql exit

postgres=# \q

 

 

firewall open

$ sudo firewall-cmd --add-service=postgresql --permanent

 

confirm

$ sudo cat /etc/firewalld/zones/public.xml

--------------------------------------------------------

<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <service name="postgresql"/>
</zone>

--------------------------------------------------------

 

firewall service restart

$ sudo firewall-cmd --reload

 

 

 

* Old Service Delete

- postgresql service stop/disable

$ sudo systemctl stop postgresql-9.6

$ sudo systemctl disable postgresql-9.6

 

- postgresql directory delete

$ sudo rm -rf /var/lib/pgsql

 

- user delete

$ sudo userdel postgres

 

- package delete

$ sudo yum remove *postgres*

728x90
반응형

'DB > PostgreSQL' 카테고리의 다른 글

CentOS7 PostgreSQL 12 earthdistance install  (0) 2020.09.10