2020年3月29日日曜日

Rocky linux 8にpostgres14をインストール

【Rocky linux9 Postgres clieant インストール 2024/1/10追記】
# dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{centos})-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# dnf install libpq-devel
or
# dnf install postgresql15-devel


【2023/12/15追記】
■Postgres client インストール
# dnf install libpq-devel
# which pg_config
/usr/bin/pg_config

ERROR
 gcc: エラー: /usr/lib/rpm/redhat/redhat-hardened-cc1: そのようなファイルやディレクトリはありません
→dnf install redhat-rpm-config


【2023/04/20更新】
■Postgre client インストール(Django)
# dnf install postgresql14-devel
# find / -print |grep pg_config
/usr/pgsql-14/bin/pg_config
$ . ./env
$ PATH=/usr/pgsql-14/bin:$PATH;export PATH
$ pip3 install psycopg2
$ ./env freeze
$ vi Config/settings.py << __EOF__
DATABASES = { 
   'default': {
     'ENGINE'       :  'django.db.backends.postgresql_psycopg2',
     'NAME'           :  'office_pg',
     'USER'            :  'admin',
     'PASSWORD':  'casio00',
     'HOST'            :  '192.168.254.201',
     'PORT'            :  '5432',
   },
}  
$ psql -U postgres -h 192.168.254.201 

■Postgre Server インストール
$  cat /etc/redhat-release
Rocky Linux release 8.7 (Green Obsidian)
# dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{centos})-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# dnf update
# dnf module list postgresql
# dnf module disable postgresql
# dnf search postgresql*-server
# dnf install -y postgresql14-server
# passwd postgres
# PGSETUP_INITDB_OPTIONS='--encoding=UTF-8 --no-locale'
# /usr/pgsql-14/bin/postgresql-14-setup initdb
# vi /var/lib/pgsql/14/data/pg_hba.conf 
#local   all             all                                   peer
local     all             all                                    trust
#host    all             all             127.0.0.1/32            ident
host all all 192.168.0.0/16                     password
# vi /var/lib/pgsql/14/data/postgresql.conf
listen_addresses = '*'          
port = 5432
# firewall-cmd --add-port=5432/tcp --zone=public --permanent
# firewall-cmd --reload
# mkdir  -p /data/postgres/data
# chown  -R postgres:postgres /data/postgres/data
# semanage fcontext -a -t postgresql_db_t "/data/postgres(/.*)?"
# grep -i postgresql /etc/selinux/targeted/contexts/files/file_contexts.local
# restorecon -R -v /data/postgres
# ls -lZR /data/postgres

(確認)
#  ls -l /var/lib/pgsql/14/data
 # vi /usr/lib/systemd/system/postgresql-14.service
#  grep -v -E "^#|^$" /var/lib/pgsql/14/data/pg_hba.conf
# grep listen_addresses /var/lib/pgsql/14/data/postgresql.conf
# ls -lZ /var/lib/pgsql
 drwx------. 4 postgres postgres system_u:object_r:postgresql_db_t:s0 51  4月 20 14:26 14

 
# systemctl start postgresql-14
# systemctl enable  postgresql-14

$ su - postgres

$ psql -U postgres
ALTER USER postgres PASSWORD 'password';

$ psql 
create user admin with password 'password' superuser;
create database ARCSDBMS owner admin;



-------------------------------------old----------------------------------------------------
# useradd admin
# su - postgres
$ postgres --version
postgres (PostgreSQL) 12.1
$ createuser admin
$ createdb testdb -O admin
$ psql  -c "select usename from pg_user;"
$ psql -l testdb
$ psql testdb
testdb=>\du
testdb=>\l
testdb=> create table test_table (no int, name text);
testdb=> insert into test_table (no,name) values (01,'CentOS');
testdb=> select * from test_table;
testdb=> drop table test_table;
testdb=>\dt
testdb=>\q
$ dropdb testdb
$ psql -l

【パスワード変更】
# vi /var/lib/pgsql/data/pg_hba.conf
local   all             all                                    peer/md5 → trust
# systemctl  restart postgresql
# su - postgres
$ psql -U postgres
postgres=# alter role postgres with password 'newpassword';

pg_hba.conf を戻す。







0 件のコメント:

コメントを投稿

シャットダウン時の後処理 (shutdown)

# vi /etc/systemd/system/drop.service [Unit] Description= stop httpgwd DefaultDependencies=no Before=shutdown.target RefuseManualStart=true ...