버젼 16
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql16-server
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
sudo systemctl enable postgresql-16
sudo systemctl start postgresql-16
sudo systemctl stop postgresql-16
버젼 15
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql15-server
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15
=======================================
systemctl stop postgresql-15
jdbc:postgresql://127.0.0.1:5456/scottdb
====root 로 기동 정지 한다.
postgresql-setup --initdb
systemctl enable postgresql.service
systemctl start postgresql.service
For RHEL / CentOS / SL / OL 6
service postgresql initdb
SELECT * FROM PG_TABLES where table owner ='
("SELECT * FROM PG_TABLES where table owner =?");
=== user 생성
adduser postgres
chown -R postgres:postgres /usr/local pgsql
vi /etc/ld.so.conf
/usr/local/pgsql/lib
======
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export PS1=`hostname`:"[\$PWD"]
PATH=$PATH:$HOME/bin:/usr/bin:/usr/pgsql-16/bin:
export PATH
export PGHOME=/usr/pgsql-16
export CLASSPATH=.:/usr/local/pgsql/jdbc/postgresql.jar녀
export MANPATH=$PGHOME/man
export PGLIB=$PGHOME/lib
export LD_LIBRARY_PATH=$PGLIB
export PGDATA=/postDATA/DATA
export PGDATA1=/postDATA1/DATA
export PGLOG=/postDATA/pg_xlog
export PGLOG1=/postDATA1/pg_xlog
export C_INCLUDE_PATH=.:/usr/local/pgsql/include/server:/usr/local/openssl/include
export LANG=ko_KR.eucKR
alias pgcfg='vi $PGDATA/postgresql.conf'
alias pcpconf='vi /usr/local/pgpool/etc/pgpool.conf'
find . -name "*pgsql*"
==================================================
postgres fdw 는 postgressql v 15 까지 지원
export PGPORT=5456
cd /usr/edb/as16/bin/
pg_ctl stop -D /var/lib/pgsql/16/data/
pg_ctl start -D /var/lib/pgsql/16/data/
find . -name pg_ctl*
./
cd /usr/edb/as16/bin/
======================================================================
사용자 데이터 베이스 생성
================================= edb db 구성
=============
db 생성 user ====
edb=# create user test;
db 생성
edb=# CREATE DATABASE scottdb OWNER test ;
alter user test identified by test;
ALTER USER test WITH PASSWORD 'test';
=====>ㅇ개ㅔ ;
[root@localhost home]# mkdir pg_data
[root@localhost home]# chown -R enterprisedb /home/pg_data
create tablespace test_ts owner test location '/home/pg_data/';
postgres-# \c testdb testuser
===> db 소유자로 접속
psql -U test -d scottdb -h localhost -p 5456
=============
=====tmzlak 생성시 주의
stdb=> create schema scott authorization test;
set search_path to "test",scottdb; <== [user명 db 명 ]
create table scott.test (test varchar2(10));
create table scott.test (test char(10));
CREATE TABLE scott.BONUS (
ENAME VARCHAR(10 ),
JOB VARCHAR(9 ),
SAL numeric,
COMM numeric
) ;
CREATE TABLE scott.BONUS (
ENAME VARCHAR(10 ),
JOB VARCHAR(9 ),
SAL numeric,
COMM numeric
) ;
CREATE TABLE scott.DEPT (
DEPTNO numeric,
DNAME VARCHAR(14 ),
LOC VARCHAR(13 ));
CREATE TABLE scott.EMP (
EMPNO numeric,
ENAME VARCHAR(10 ),
JOB VARCHAR(9 ),
MGR numeric,
HIREDATE DATE,
SAL numeric,
COMM numeric,
DEPTNO numeric);
create synonym BONUS for scott.BONUS;
create synonym DEPT for scott.DEPT;
create synonym EMP for scott.EMP;
===================imp 작업
edbldr -d scottdb -p 5444 -h localhost userid=test/test control=/var/lib/edb/data/EMP.ctl log=/var/lib/edb/data/dept.log bad=/var/lib/edb/data/baddept.log
edbldr -d scottdb -p 5444 -h localhost userid=test/test control=/var/lib/edb/data/DEPT.ctl log=/var/lib/edb/data/DEPT.log bad=/var/lib/edb/data/badDEPT.log
psql -U test -d scottdb -h localhost -p 5444
===========================================티베로 에서 source 가 추출이 안될경우select test from dba_sources; 에서 추출
Listagg
========================
pg loder 설치
https://ftp.postgresql.org/pub/projects/pgFoundry/pgloader/pgloader/2.3.2/pgloader-2.3.2.tar.gz
====pgsql rpm 버젼
wget https://rpmfind.net/linux/opensuse/distribution/leap/15.5/repo/oss/aarch64/pgloader-3.6.9-bp155.1.26.aarch64.rpm
https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/pgloader/3.6.9-1/pgloader_3.6.9.orig.tar.gz
설치 하기
docker run --rm -it dimitri/pgloader:latest pgloader --version
====이걸로 설치
make save
make pgloader
=====================
POSTGRES_HOME=/db/pgsql
export POSTGRES_HOME
# PostgreSQL Home Path
PGDATA=/db/data
export PGDATA
# PostgreSQL Data Path
LD_LIBRARY_PATH=/home/dbadmin/pgsql/lib
export LD_LIBRARY_PATH
# PostgreSQL Library Path
PATH=$POSTGRES_HOME/bin:$PATH
export PATH
PGPASSWORD=test psql -U test -d scottdb -h localhost -p 5456 < song.sql
select table_name ,
column_name ,
data_type ,
character_maximum_length , is_nullablefrom information_schema.columns where table_name = 'DEPT'order by ordinal_position
select * from
information_schema.tables
where table_name='dept';
SELECT
TABLE_NAME as 테이블이름,
column_name as 컬럼명,
is_nullable as null가능여부,
data_type as 데이터타입,
character_maximum_length as 최대길이,
character_octet_length,
numeric_precision,
numeric_precision_radix,
numeric_scale
WHERE
--TABLE_CATALOG = 'scottdb'
--and table_schema = 'SCOTT'
--and
table_name = 'DEPT'
ORDER BY 테이블이름, ORDINAL_POSITION;
===========================psql 기본 명령어
psql -? : 옵션 목록 및 도움말을 확인할 수 있습니다.
\l or \list + +: 데이터베이스 목록을 보여줍니다. +를 붙여 자세한 내용을 확인할 수 있습니다.
\d or \dt+ + :d 테이블, 인덱스, 시퀀스, 뷰 목록을 보여줍니다. +를 붙여 자세한 내용을 확인할 수 있습니다.
\d [table] : 해당 테이블의 정보(컬럼 목록)를 보여줍니다.
\di : 인덱스 목록을 보여줍니다.
\ds : 모든 시퀀스 정보를 보여줍니다.
\df : 모든 함수 정보를 보여줍니다.
\dv : 모든 뷰 테이블 정보를 보여줍니다.
\dg or \du : 등록된 사용자 권한 정보 목록을 보여줍니다.
\dn : 스키마 목록을 보여줍니다.
\dS : 시스템 테이블 목록을 보여줍니다.
\h : 간단한 구성의 SQL 사용법을 확인할 수 있습니다.
\e : psql.edit 파일이 열려 query를 수정하고 실행할 수 있습니다.
\c or \connect + [database] : 다른 데이터베이스에 접속합니다.
\c [database] [user] : 다른 데이터베이스에 지정한 사용자로 접속합니다.
\q : psql 종료
scottdb-# \d INFORMATION_SCHEMA.COLUMNS
select
column_name ,
ordinal_position ,
column_default ,
is_nullable ,
data_type ,
character_maximum_length ,
numeric_precision
from information_schema.columns
where table_name ='dept';
select *
from information_schema.columns
where table_name ='dept';
=================linux 방화벽
firewall-cmd --query-port=5456/tcp
firewall-cmd --add-port=5456/tcp --permanent
sudo firewall-cmd --query-port=5456/tcp
===================================
치명적오류: 호스트 "192.168.52.1", 사용자 "test", 데이터베이스 "scottdb", 암호화 안함 연결에 대한 설정이 pg_hba.conf 파일에 없습니다.
치명적오류: 호스트 "192.168.52.1", 사용자 "test", 데이터베이스 "scottdb", 암호화 안함 연결에 대한 설정이 pg_hba.conf 파일에 없습니다.
================
192.168.52.165
host all all 0.0.0.0/0 scram-sha-256
Connection to 192.168.52.165:5456 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection refused: no further information
Connection refused: no further information
port 체크
etstat -tnlp
/usr/pgsql-16/bin/pg_ctl start -D /var/lib/pgsql/16/data
/usr/pgsql-16/bin/pg_ctl stop -D /var/lib/pgsql/16/data
/var/lib/pgsql/16/data/pg_hba.conf
ls -ltr | tail -1
path 추가..
export PATH=.:$TB_HOME/bin:$TB_HOME/client/bin:$JAVA_HOME:$PATH:/var/lib/pgsql/run:
/var/lib/pgsql/run
cd $PGDATA/log /var/lib/pgsql/16/data/log
==============logpg
aaaa=$(find $PGDATA/log -ctime -5 -type f |head -1)
echo $aaaa
tail -f $aaaa
=======================startpg
/usr/pgsql-16/bin/pg_ctl start -D /var/lib/pgsql/16/data
ps -ef |grep postgres
=======================stop pg
/usr/pgsql-16/bin/pg_ctl start -D /var/lib/pgsql/16/data
ps -ef |grep postgres
SELECT pg_column_size('LINESTRING(1 2,3 4, 5 6)'::geometry);
coalesce(name, 'NONE')
PGPASSWORD=${PG_PASSWORD} psql -U ${PG_USER} -d ${PG_DATABASE} -h ${PG_PORT} -p ${PG_PORT} < song.sql