레이블이 show인 게시물을 표시합니다. 모든 게시물 표시
레이블이 show인 게시물을 표시합니다. 모든 게시물 표시

2019년 5월 3일 금요일

PostgreSQL SET session

PostgreSQL 에 클라이언트로 접속 후,
SET 명령어를 통해 환경설정 값을 변경할 수 있다.

변경을 하면, 현재 자신이 연결된 session 에만 영향을 준다.
다른 session 에는 영향을 주지 않는다.
물론, session 이 close 되면, 환경설정 값들은 사라지게 된다.

session 으로 연결된 상태에서 환경설정 값을 변경할 수 있다.
모든 환경설정이 다 되는 것은 아니다.

context 가 superuser 혹은 user 인 환경설정만 가능하다.
superuser 인 것은 superuser 권한이 있어야 한다.

postgres=# select name,setting,context from pg_settings where context = 'superuser' or context = 'user';


set 으로 변경이 불가능한 환경설정인 경우에는 에러가 발생한다.

ERROR:  parameter "allow_system_table_mods" cannot be changed without restarting the server

set 으로 변경 가능한 환경설정 중에서 'wal_compression' 을 변경해 보자.

현재 off 값이 셋팅되어 있다.
3가지 방법으로 확인할 수 있다.
3가지 방법 중 원하는 방법으로 확인하면 된다.

postgres=# select name,setting,context from pg_settings where name = 'wal_compression';

postgres=# show wal_compression;

postgres=# select current_setting('wal_compression');


postgres=# set session wal_compression = on;

postgres=# select name,setting,context from pg_settings where name = 'wal_compression';

postgres=# show wal_compression;

postgres=# select current_setting('wal_compression');


set session 말고, set local 옵션도 있다.
set local 은 transaction 안에서만 사용할 수 있고, transaction 안에서만 유효하다.
transaction 안에서만 사용할 수 있다고 메세지가 나온다.


transaction 안에서만 사용 가능하고, transaction 이 끝나면 다시 원래대로 돌아온다.


transaction 안에서 set session 을 수행하면, commit 여부에 따라 결과가 달라진다.
rollback 을 수행하면 적용되지 않는다.


commit 을 수행하면 적용된다.


※ set 다음에 session, local 을 생략할 수 있다. 생략을 하면 session 으로 동작하게 된다.

set 대신에 set_config() 를 사용할 수 있다.
함수 원형은 아래와 같다.
set_config(setting_name, new_value, is_local)

세번째 인자 값에 따라 결과가 달라진다.




출처
https://www.postgresql.org/docs/10/sql-set.html
https://www.postgresql.org/docs/10/sql-show.html
https://www.postgresql.org/docs/10/config-setting.html
https://www.postgresql.org/docs/10/runtime-config.html
https://www.postgresql.org/docs/10/functions-admin.html

2019년 4월 29일 월요일

PostgreSQL show all, show name

current session에 설정되어 있는 run-time parameters 값들을 확인하려면 show 명령어를 사용하면 된다. description 도 같이 출력된다.

postgres=# show all


이 값들은
SET 문을 사용하거나,
postgresql.conf 구성 파일을 편집하거나,
PGOPTIONS 환경 변수를 설정하거나(libpq 또는 libpq 기반 응용 프로그램을 사용하는 경우),
postgres 서버를 시작할 때 명령 행 플래그를 통해 설정,
해서 setting 되어 있는 값들이다.

결론은, 이렇게 저렇게 뭐 해서, 최종적으로 current session 에 setting 되어 있는 값들이다.

모든 설정값 말고, 특정 설정값만 출력하고 싶다면 이름을 넣으면 된다.

postgres=# show allow_system_table_mods;


사용자가 임의로 설정할 수 없으나, 운영에 필요한 몇 가지 환경설정이 자동으로 설정된다.
대소문자 상관없다.

SERVER_VERSION
서버 버전을 표시한다.

SERVER_ENCODING
서버 측 문자 인코딩을 표시한다.
데이터베이스 생성시 결정된다.

LC_COLLATE
데이터 정렬에(텍스트 순서 지정) 대한 로케일 설정을 표시한다.
데이터베이스 생성시 결정된다.

LC_CTYPE
문자 분류에 대한 로케일 설정을 표시한다.
데이터베이스 생성시 결정된다.

IS_SUPERUSER
superuser 인지 표시한다.


show 명령어 대신에, current_setting 명령어도 사용 가능하다.

postgres=# select current_setting('allow_system_table_mods');




출처
https://www.postgresql.org/docs/10/sql-show.html
https://www.postgresql.org/docs/10/functions-admin.html

화곡 어쩌라고, 굴사냥

석화찜(굴찜)을 먹으러 여의도로 갔다 그런데 재료가 모두 소진되었다고 마감이라고 한다 응? 다들 굴에 미쳤나? 굴을 찾아 헤매다 보니, 화곡까지 가게 되었다. 화곡은 처음 가본다. 첫인상은 "술집 겁네 많네" 피똥쌀때까지 마실 수 있...