C macro 사용 시 주의사항

C/C++ 2014. 12. 3. 11:18
C 코딩 간 macro 사용 시 연산자 우선순위를 고려하여 괄호처리를 해주는 것이 좋습니다.
아래는 잘못된 macro 설정사례입니다.
#define DANGER 60 + 2
위 사례는 아래와 같은 상황에서 잘못된 결과를 초래할 수 있습니다.
int wrong_value = DANGER * 2; //  124라는 결과 값 대신 60 + 2 * 2 = 64 가 할당됩니다.
괄호처리를 하여 아래와 같이 사용해야 합니다.
#define HARMLESS (60 + 2)

'C/C++' 카테고리의 다른 글

런타임 OS 식별 팁  (0) 2009.11.10

md5를 이용한 password hash value 구하기

POSTGRESQL 2014. 11. 26. 11:17
1. pgcrypto extension 을 생성합니다.
estdb=# create extension pgcrypto;
CREATE EXTENSION
testdb=# create table user_info(user_id varchar(30), password varchar(100));
CREATE TABLE
testdb=# insert into user_info values('id1', crypt('id1_password', gen_salt('md5')));
INSERT 0 1
testdb=# insert into user_info values('id2', crypt('id2_password', gen_salt('md5')));  
INSERT 0 1

 

2. 데이터를 조회할 때는 아래와 같이 SQL을 작성합니다.
testdb=# select user_id from user_info where user_id='id1' 
            and password = crypt('id1_password', password);
 user_id 
---------
 id1
(1 row)

testdb=# 

[9.4 beta]ALTER SYSTEM 구문을 이용한 파라메터 변경

POSTGRESQL 2014. 10. 29. 17:11
9.4 에 새롭게 적용될 ALTER SYSTEM 구문을 테스트해 보았습니다.
요약하자면 ALTER SYSTEM 구문을 통해 변경된 파라메터 이름과 value 는 postgresql.auto.conf 파일에 저장되며,
SQL 함수인 pg_reload_conf() 를 통해 reload 되는 방식입니다.
pg_settings 시스템뷰에서 정의하는 context 속성은 그대로 적용된듯 합니다.

1. ALTER SYSTEM 구문으로 파라메터값을 변경합니다.
(pg_reload_conf 함수 또는 pg_ctl reload 를 실행전까지 적용되지 않습니다.)
pg_test=# select context,name,setting from pg_settings
where name in ('enable_seqscan','authentication_timeout','max_connections');
  context   |          name          | setting 
------------+------------------------+---------
 sighup     | authentication_timeout | 60
 user       | enable_seqscan         | on
 postmaster | max_connections        | 100
(3 rows)

pg_test=# ALTER SYSTEM set authentication_timeout=30;
ALTER SYSTEM
pg_test=# ALTER SYSTEM set enable_seqscan = off;
ALTER SYSTEM
pg_test=# ALTER SYSTEM set max_connections = 1000;
ALTER SYSTEM
pg_test=# select context,name,setting from pg_settings
where name in ('enable_seqscan','authentication_timeout','max_connections');
  context   |          name          | setting 
------------+------------------------+---------
 sighup     | authentication_timeout | 60
 user       | enable_seqscan         | on
 postmaster | max_connections        | 100
(3 rows)


2. pg_reload_conf() 함수를 통해 reload 명령을 실행하고, 해당 파라메터의 변경된 값을 확인합니다.
(단, pg_settings.context 값이 postmaster인 경우 서버를 재기동해야 합니다.)
pg_test=# select pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 row)

pg_test=# select context,name,setting from pg_settings
where name in ('enable_seqscan','authentication_timeout','max_connections');
  context   |          name          | setting 
------------+------------------------+---------
 sighup     | authentication_timeout | 30
 user       | enable_seqscan         | off
 postmaster | max_connections        | 100
(3 rows)


3. reset 또는 default 구문을 이용하여 postgresql.conf 파일에 저장된 값으로 초기할 수 있습니다.
pg_test=# ALTER SYSTEM reset authentication_timeout;
ALTER SYSTEM
pg_test=# select pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 row)
pg_test=# select context,name,setting from pg_settings
where name in ('enable_seqscan','authentication_timeout','max_connections');
  context   |          name          | setting 
------------+------------------------+---------
 sighup     | authentication_timeout | 60
 user       | enable_seqscan         | off
 postmaster | max_connections        | 100
 


4. reset all 구문을 이용하여 모든 파라메터를 postgresql.conf 파일에 저장된 값으로 초기화 할 수 있습니다.
pg_test=# ALTER SYSTEM reset all;
ALTER SYSTEM

pg_test=# select pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 row)

pg_test=# select context,name,setting from pg_settings
where name in ('enable_seqscan','authentication_timeout','max_connections');
  context   |          name          | setting 
------------+------------------------+---------
 sighup     | authentication_timeout | 60
 user       | enable_seqscan         | on
 postmaster | max_connections        | 100
(3 rows)


※ data_directory파라메터와 block_size 등과 같이 context 구분이 internal인 파라메터는 변경할 수 없습니다.
pg_test=# alter system set data_directory='/data';
ERROR:  parameter "data_directory" cannot be changed

'POSTGRESQL' 카테고리의 다른 글

prepare statements 와 casting  (0) 2015.04.21
md5를 이용한 password hash value 구하기  (0) 2014.11.26
table inheritance(상속)  (0) 2014.10.28
max_connections 와 커널파라메터  (0) 2014.10.27
postgresql DBLINK 예제  (0) 2014.10.27