728x90

Postgresql SSL 적용

 

[postgresql.conf] 

ssl = on

[pg_hba.conf] 

hostnossl : ssl 미적용 접근 설정

hostssl : ssl 적용 접근 설정

아래설정 : localhost는 ssl 없이 접속, 그외에 ssl 적용

hostnossl  all         all        127.0.0.1/32       trust
hostssl    all         all        127.0.0.1/32       reject
hostssl    all         all        192.168.2.0/24     scram-sha-256

[ssl 인증서파일] postgresql.conf 같은 폴더에 복사

server.crt
server.key

[postgresql 재시작]

sudo systemctl restart postgresql

[연결 확인] 클라이언트에서 접속

$ psql -d "dbname=postgres sslmode=require" -h postgresql.example.com -U postgres

Password for user mctdba:
psql (15.2, server 14.6)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.
postgres=#

[연결 확인] postgresql 서버

$ psql
postgres=# SELECT ssl.pid, usename, datname, ssl, ssl.version, ssl.cipher, ssl.bits, client_addr FROM pg_catalog.pg_stat_ssl ssl, pg_catalog.pg_stat_activity activity WHERE ssl.pid = activity.pid;
  pid  | usename  |    datname     | ssl | version |           cipher            | bits | client_addr
-------+----------+----------------+-----+---------+-----------------------------+------+--------------
 10728 | mctdba   | RealOffice_MCT | t   | TLSv1.2 | ECDHE-RSA-AES256-GCM-SHA384 |  256 | 127.0.0.1
  8468 | mctdba   | RealOffice_MCT | t   | TLSv1.3 | TLS_AES_256_GCM_SHA384      |  256 | 접속자IP

[적용 후 jdbc 설정]

jdbc:postgresql://localhost:5432/postgres?sslmode=require
728x90
728x90

 

postgresql 주말을 제외한 한 달의 모든 요일 얻기

 

select dt 
from generate_series(date'2019-11-01', date'2019-11-30', interval '1' day) as t(dt)
where extract(dow from dt) between 1 and 5;

sql result

https://stackoverflow.com/questions/59489628/get-all-days-in-a-month-excluding-weekends-postgresql

 

Get all days in a month excluding weekends postgresql

I want to write a query sql for postgresql that can basically return me all days of a month excluding weekends. For example (For 11/2019) : First Week: 11/1 Second Week : 11/4 -> 11/8 Third Wee...

stackoverflow.com

 

728x90

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

Postgresql SSL 적용  (0) 2023.04.03
Postgresql 15 user create 유저생성  (0) 2023.03.29
Postgresql 쉼표로 구분된 열을 행으로 변환  (0) 2023.03.29
728x90

Postgresql 15 user create 유저생성

postgresql 15버전에서 기본 유저 및 데이터 베이스를 생성했는데 public 스키마에 접근이 불가능해서 구글링해보니

15버전부터는 public 스키마에 권한을 따로 줘야 했다.

CREATE DATABASE testuser;

CREATE USER testuser WITH ENCRYPTED PASSWORD 'password';

GRANT ALL PRIVILEGES ON DATABASE testuser TO testuser;

GRANT ALL ON SCHEMA public TO testuser;

GRANT ALL ON DATABASE testuser TO testuser;

ALTER DATABASE testuser OWNER TO testuser;

GRANT USAGE, CREATE ON SCHEMA public TO testuser;

https://stackoverflow.com/questions/74110708/postgres-15-permission-denied-for-schema-public

 

Postgres 15. permission denied for schema public

Can't create tables in public schema as non-superuser postgres - super user. What I've done: ALTER SCHEMA public owner to postgres; CREATE USER admin WITH PASSWORD 'my-password'; GRANT USAGE,

stackoverflow.com

 

728x90
728x90

Postgresql 콤마로 구분된 데이터 열을 행으로 변환

 

변환 전
변환 후

SQL

with temp01 as (
	select 1 as  idx
		, '가,나,다' as col01
	union
	select 2 as  idx
		, '라,마,바' as col01
)
select idx,
       unnest(string_to_array(col01, ',')) as col01
from temp01
order by idx asc;

출처 : https://medium.com/swlh/three-routes-convert-comma-separated-column-to-rows-c17c85079ecf

728x90

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

Postgresql SSL 적용  (0) 2023.04.03
postgresql 주말을 제외한 한 달의 모든 요일 얻기  (0) 2023.03.29
Postgresql 15 user create 유저생성  (0) 2023.03.29

+ Recent posts