기본 콘텐츠로 건너뛰기

우분투 PostgreSQL 설치

참조 사이트
http://zetawiki.com/wiki/%EC%9A%B0%EB%B6%84%ED%88%AC_PostgreSQL_%EC%84%A4%EC%B9%98


1. 설치 확인

aptitude show postgresql | grep State
State: not installed

2. 설치

apt-get install postgresql

3. 확인

dpkg -l | grep postgres
4. 계정 확인
cat /etc/passwd | grep postgres
postgres:x:110:120:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
네트웍 상태 확인
netstat -tnlp | grep postgres

패스워드 설정
sudo -u postgres psql template1
could not change directory to "/root": Permission denied
psql (9.3.11)
Type "help" for help.

template1=#
template1=# ALTER USER postgres with encrypted password 'P@ssw0rd';
ALTER ROLE
template1=# \q

접속 모든 대역 허용
vi /etc/postgresql/9.3/main/postgresql.conf
listen_addresses = '*'

vi /etc/postgresql/9.3/main/pg_hba.conf
host    all             all             0.0.0.0/0               md5

접속 테스트

psql -h 135.79.246.80 -U postgres template1

접속 db 포함 접속
#psql -h 127.0.0.1 -U postgres customsinsa

다른 DB 접속
postgres=# use customsinsa;

테이블 보기
customsinsa=# \d

컴럼 정보 보기
customsinsa=# \d testa

뷰목록
\dv

DB 목록
\l

종료
\q

아래 참조: http://wwwi.tistory.com/347
● 데이터 베이스 사용자 만들기

create user wwwi with password 'wwwi';


버전 확인
select version();

● 데이터베이스  만들기

create database wwwi;

● 테이블 만들기

create table testa (
  key          char(16) primary key,
  val1        integer,
  val2        integer
);

  *테이블 만들 때에  NOT NULL 제약(NULL Data 입력 금지),
  UNIQUE 제약, (동일한 Data 입력 금지)
  DEFAULT 초기값 설정가능

create table testa (
  key          char(16) primary key,
  val1        integer not null,
  val2        integer unique,
  val3        integer default 0 not null
);

  *constraint으로 Primary Key를 설정하거나 복수의 Primary Key는
  아래와 같은 방법으로 설정

create table testa (
  key          char(16),
  val1        integer,
  val2        integer,
  constraint PK_NAME primary key (
    key,
    val1
  )
);

● 테이블 지우기

drop table testa;

● 기본적인 필드 타입

    smailint                           2 바이트 정수
    integer                            4 바이트 정수
    bigint                             8 바이트 정수
    decimal(a, a)/numeric(a, s)        10진수형
    real                               6자리 단정도 부동소수점
    double precision                   15 자리 배정도 부동소수점
    serial                             4 바이트 일련번호
    bigserial                          8 바이트 일련번호
    date                               일자
    time                               시간
    timestamp                          일자시간
    char(문자수)/character             고정길이 문자열  (최대 4096 문자)
    varchar(문자수)/charcter varying   가변길이 문자열  (최대 4096 문자)
    text                               무제한 텍스트
    Large Object                       oid형
    boolean/bool                       true/false

● 키 만들기

  *단일 키 설정은 테이블 만들 때에 create table에서 하는 편이 좋다.
    단일 키를 설정할 필드에 primary key를 지정하면 된다.

  key          char(16)     primary key,

  *복수 키는 아래와 같이 추가할 수 이싿.

create table testa (
  key          char(16),
  val1        integer,
  val2        integer,
  constraint PK_NAME primary key (
    key,
    val1
  )
);

  * 인덱스를 추가하면 검색 속도를 빠르게 할 수 있지만 너무 많이 만들면
    갱신할 때에 부하가 걸릴 수 있다.
 
create unique index PK_NAME on testa (
  key,
  val1
);

create index PK_NAME on testa (
  key,
  val1
);

● 키 지우기

drop index PK_NAME;

● 일련번호  만들기

  *일변번호는 serial로 정의해서 사용할 수 있음

create table testa (
  key          char(16),
  val1        serial,
  val2        integer,
);

insert into testa values('key00A');
insert into testa values('key00B');

   key      | val1 | val2
--------+----+------
 key00A   |    1 |    
 key00B   |    2 |    


create sequence seq;

  *다음과 같이 만들면 10 ~ 1000000, 100씩 증가하며 최대값이 되면 다시 최소값으로 돌아간다.

create sequence seq
  increment    10
  minvalue     10
  maxvalue     1000000
  start        10
  cache        100
  cycle
;

  *일련번호는 다음과 같이 사용한다.
    nextval이 일련번호를 만들어 내고
    currval은 일변번호의 현재값을 가져온다.

insert into testa values ('k001', nextval('seq'), 10);
insert into testa values ('k002', nextval('seq'), 10);
insert into testa values ('k003', currval('seq'), 10);

   key    | val1 | val2
------+-----+------
 k001     | 10   |   10
 k002     | 20   |   10
 k003     | 20   |   10

● 일련번호  지우기

drop sequence seq;

댓글

이 블로그의 인기 게시물

톰캣 세션 타임 아웃 설정

web.xml 파일이 있습니다. 이 파일을 열어서 session이라고 검색해 보십시오. <session-config>   <session-timeout>360</session-timeout> </session-config> 위 단락을 찾을 수 있습니다. session-timeout 시간 360이 바로 자동로그아웃 세션 시간입니다.  단위는 분이고요. 30분으로 하고 싶으시면 30으로 바꿔서 저장해주시면 되는 것이죠~ Tomcat 내에서 Session Timeout 를 설정하는 우선 순위가 존재 한다. session.setMaxInactiveInterval() 프로그램내에서 time out 를 설정했을 경우 Web application 내의 WEB-INF/web.xml Tomcat 내의 conf/web.xml 실제로 Tomcat(conf/web.xml)내에 Default 로 설정되어 있는 것은 다음과 같다. < HttpSession 메서드 > getCreationTime() - 세션 생성 시간 getLastAccessedTime() - 마지막 요청 시간 setMaxInactiveInterval() - 최대허용시간 설정 (초) getMaxInactiveInterval() - 최대허용시간 invalidate() - 세션 제거 < 타임아웃 설정하기 > - 일정 시간 동안 요청이 없으면 세션을 제거한다  1. DD에서 전체 세션 타임아웃 설정       web.xml 1. DD에서 전체 세션 타임아웃 설정       web.xml <web-app ... >     <servlet>          ...     </servlet>     <session-config>         <session-timeout>30</session-timeout>

dmesg 메시지 실시간으로 보기

참조사이트 http://imitator.kr/Linux/556 # tail -f /var/log/messages # tail -f |dmesg //기본 2초 단위로 갱신 된다. # watch "dmesg | tail -f" //1초 단위로 갱신하면서 보여준다. # watch -n 1 "dmesg | tail -f" // 보여주는 줄을 20으로 늘린다. (기본 10줄) # watch -n 1 "dmesg | tail -f -n 20"

kernel Hello World

리눅스 커널 모듈 프로그래밍 가이드 참조:http://www.tldp.org/LDP/lkmpg/2.6/html/lkmpg.html 커널 모듈 가이드 아래 테스트는 우분투 14.04에서 테스트 되었습니다. 모듈 유틸리티 insmod:모듈을 커널에 적재한다. rmmod:커널에서 모듈을 제거한다. lsmod:커널에서 적재된 모듈 목록을 보여준다. depmod: 모듈간 의존성 정보를 생성한다. modprobe:모듈을 커널에 적재하거나 제거한다. modinfo rdma_ucm 모듈 정보 보기: #lsmod #cat /etc/modprobe.conf #modinfo ib_core 커널에서 제공하는 심볼 테이블 :커널 내부의 함수나 변수 중 외부에서 참조할 수 있는 함수의 심볼과 주소를 담은 테이블 #cat /proc/kallsyms 커널 모듈 제작해 보기 kernel ver 3.16 hello.c /*  *  hello.c - The simplest kernel module.  */ # #include <linux/module.h> #include <linux/kernel.h> int init_module(void) { printk("<1>Hello World 1.\n"); return 0; } void cleanup_module(void) { printk(KERN_ALERT "Goodbye world 1.\n"); } Makefile obj-m += hello.o all:         make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean:         make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean #make make -C /lib/modules/3