1. bench test
SELECT pg_stat_statements_reset();
pgbench -i bench
pgbench -c10 -t300 bench
pgbench -c 4 -T 50 spprs
2. 임의의 데이터 생성
-- 연속된 1 ~ 5값 생성
SELECT * FROM generate_series(1,5);
-- 현재 기준으로 1일씩 더해서 7일 데이터 생성
SELECT date(generate_series(now(), now() + '1 week', '1 day'))
-- integer 생성
SELECT (random()*(2*10^9))::integer;
-- bigint 생성
SELECT (random()*(9*10^18))::bigint
-- numeric 생성
SELECT random()*100.)::numeric(4,2)
-- random 길이 string 생성
select repeat('1',(random()*40)::integer)
-- list string으로 부터 임의 string 선택
select (ARRAY['one','two','three'])[0.5+random()*3]
-- 임의 데이터 생성
SELECT generate_series(1,10) as key,(random()*100.)::numeric(4,2),repeat('1',(random()*25)::integer);
SELECT generate_series(1,10) as key,(random()*100.)::numeric(4,2),repeat('1',(random()*25)::integer)ORDER BY random();
-- 기존 테이블에서 10% 데이터 추출
select * from test1 where random() < 0.1
3. data dump
pg_dump --exclude-table=test1 > db.dmp -- test1를 제외한 데이터 dump
=> psql -f db.dmp -- load
pg_dump --table=test1 --schema-only > test.schema
=> psql -f test.schema
psql -c '\copy (select * from test1 where random() < 0.1) to test.dat'
=> psql -c '\copy test1 from test.dat'
4. data load
psql -c '\COPY sample FROM sample.csv CSV HEADER' -- csv header 무시
COPY sample FROM '/mydatafiledirectory/sample.csv' CSV HEADER;
pgloader : http://github.com/dimitri/pgloader
LOAD CSV
FROM 'GeoLiteCity-Blocks.csv' WITH ENCODING iso-646-us
HAVING FIELDS
(
startIpNum, endIpNum, locId
)
INTO postgresql://user@localhost:54393/dbname?geolite.blocks
TARGET COLUMNS
(
iprange ip4r using (ip-range startIpNum endIpNum),
locId
)
WITH truncate,
skip header = 2,
fields optionally enclosed by '"',
fields escaped by backslash-quote,
fields terminated by '\t'
SET work_mem to '32 MB', maintenance_work_mem to '64 MB';
pgloader --summary summary.log example.load
'RDB > PostreSQL' 카테고리의 다른 글
PostgreSQL objects (0) | 2016.03.16 |
---|---|
postgresql replication (0) | 2015.12.14 |
postgresql 모니터링 (0) | 2015.12.08 |
오픈소스 모니터링툴 (0) | 2015.12.08 |
Postgresql 기본 사용법 (0) | 2015.12.07 |