MySQL에서 PostgreSQL 8.2로 데이터베이스 전환2007년 10월, Scott Fehrman 목차:
MySQL을 가끔 사용해 온 사용자 중 한 명으로서, Solaris 10 8/07 OS가 PostgreSQL에 대한 지원이 업데이트되어 공식적으로 출시되었으므로 이 제품을 사용해 보고 MySQL 사용자가 PostgreSQL을 시작하기 위해 무엇이 필요한지 알아보기로 했습니다. 이 Solaris 10 릴리스의 몇 가지 PostgreSQL 기능 및 개선 사항은 다음과 같습니다.
이 Solaris 10 릴리스의 새로운 PostgreSQL 기능 및 개선 사항 목록은 아래를 참조하십시오. Sun PostgreSQL 공식 웹 페이지에서 보다 자세한 내용을 확인할 수 있습니다. 시작하기기본적으로 PostgreSQL 서비스는 다음과 같이 사용할 수 없도록 설정되어 있습니다. # svcs postgresql STATE STIME FMRI disabled Sep_06 svc:/application/database/postgresql:version_81 disabled Sep_06 svc:/application/database/postgresql:version_82 #
참고: 자세한 내용을 알아보기 전에
또한 Solaris 10 8/07 OS에는 미리 구성된 # grep postgres /etc/user_attr
postgres::::type=role;profiles=Postgres Administration,All
# su - postgres
$ id
uid=90(postgres) gid=90(postgres)
$ profiles
Postgres Administration
All
Basic Solaris User
$ profiles -l
Postgres Administration:
/usr/postgres/8.2/bin/initdb uid=postgres
/usr/postgres/8.2/bin/ipcclean uid=postgres
/usr/postgres/8.2/bin/pg_controldata uid=postgres
/usr/postgres/8.2/bin/pg_ctl uid=postgres
/usr/postgres/8.2/bin/pg_resetxlog uid=postgres
/usr/postgres/8.2/bin/postgres uid=postgres
/usr/postgres/8.2/bin/postmaster uid=postgres
....
$
PostgreSQL을 사용하기 전에 먼저 설정해야 합니다. 다음과 같은 몇 가지 간단한 작업이 필요합니다.
환경 설정(8.2 버전)
데이터베이스 초기화(8.2 버전)
PostgreSQL 데이터베이스를 시작하기 전에 "처음"으로 초기화해야 합니다. # su - postgres
$ /usr/postgres/8.2/bin/initdb -D /var/postgres/8.2/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale C.
fixing permissions on existing directory /var/postgres/8.2/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers/max_fsm_pages ... 32MB/204800
creating configuration files ... ok
creating template1 database in /var/postgres/8.2/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
Success. You can now start the database server using:
/usr/postgres/8.2/bin/postgres -D /var/postgres/8.2/data
or
/usr/postgres/8.2/bin/pg_ctl -D /var/postgres/8.2/data -l logfile start
$
참고: 데이터베이스 서비스 시작(8.2 버전)
PostgreSQL 데이터베이스를 시작할 준비가 되었습니다. # su - postgres $ svcs postgresql STATE STIME FMRI disabled Sep_06 svc:/application/database/postgresql:version_81 disabled 14:06:11 svc:/application/database/postgresql:version_82 $ svcadm -v enable -s postgresql:version_82 svc:/application/database/postgresql:version_82 enabled. $ svcs -l postgresql:version_82 fmri svc:/application/database/postgresql:version_82 name PostgreSQL RDBMS enabled true state online next_state none state_time Fri Sep 14 14:23:49 2007 logfile /var/svc/log/application-database-postgresql:version_82.log restarter svc:/system/svc/restarter:default contract_id 379 dependency require_all/none svc:/milestone/network:default (online) dependency require_all/none svc:/system/filesystem/local:default (online) $ Solaris Service Management Facility는 시스템이 부팅될 때 PostgreSQL 데이터베이스를 자동으로 시작합니다. 데이터베이스 사용(8.2 버전)대화형, 명령줄, 작업을 위한 주 PostgreSQL 명령은
$ /usr/postgres/8.2/bin/psql --help
This is psql 8.2.4, the PostgreSQL interactive terminal.
Usage:
psql [OPTIONS]... [DBNAME [USERNAME]]
General options:
-d DBNAME specify database name to connect to (default: "postgres")
-c COMMAND run only single command (SQL or internal) and exit
-f FILENAME execute commands from file, then exit
-1 ("one") execute command file as a single transaction
-l list available databases, then exit
-v NAME=VALUE set psql variable NAME to VALUE
-X do not read startup file (~/.psqlrc)
--help show this help, then exit
--version output version information, then exit
Input and output options:
-a echo all input from script
-e echo commands sent to server
-E display queries that internal commands generate
-q run quietly (no messages, only query output)
-o FILENAME send query results to file (or |pipe)
-n disable enhanced command line editing (readline)
-s single-step mode (confirm each query)
-S single-line mode (end of line terminates SQL command)
-L FILENAME send session log to file
Output format options:
-A unaligned table output mode (-P format=unaligned)
-H HTML table output mode (-P format=html)
-t print rows only (-P tuples_only)
-T TEXT set HTML table tag attributes (width, border) (-P tableattr=)
-x turn on expanded table output (-P expanded)
-P VAR[=ARG] set printing option VAR to ARG (see \pset command)
-F STRING set field separator (default: "|") (-P fieldsep=)
-R STRING set record separator (default: newline) (-P recordsep=)
Connection options:
-h HOSTNAME database server host or socket directory (default: "local socket")
-p PORT database server port (default: "5432")
-U NAME database user name (default: "postgres")
-W prompt for password (should happen automatically)
For more information, type "\?" (for internal commands) or "\help"
(for SQL commands) from within psql, or consult the psql section in
the PostgreSQL documentation.
Report bugs to
대화형 터미널 모드에 들어가려면 $ /usr/postgres/8.2/bin/psql
Welcome to psql 8.2.4, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
postgres=#
테이블 만들기: postgres=# CREATE TABLE location ( CODE VARCHAR(8) NOT NULL PRIMARY KEY, DESCRIPTION VARCHAR(32) NOT NULL ); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "location_pkey" for table "location" CREATE TABLE 테이블 설명: postgres=# \dt
List of relations
Schema | Name | Type | Owner
--------+----------+-------+----------
public | location | table | postgres
(1 row)
테이블 채우기: postgres=# INSERT INTO location ( CODE, DESCRIPTION ) VALUES
('loc30','Austin, Texas'),
('loc31','New York, New York'),
('loc32','Chicago, Illinois'),
('loc33','Dallas, Texas'),
('loc34','San Jose, California'),
('loc35','Atlanta, Georgia'),
('loc99','Denver, Colorado');
INSERT 0 7
테이블 선택: postgres=# select * from location; code | description -------+---------------------- loc30 | Austin, Texas loc31 | New York, New York loc32 | Chicago, Illinois loc33 | Dallas, Texas loc34 | San Jose, California loc35 | Atlanta, Georgia loc99 | Denver, Colorado (7 rows) 테이블 삭제: postgres=# drop table location; DROP TABLE 데이터베이스 중지(8.2 버전)
PostgreSQL 데이터베이스를 중지하려면 다음과 같이 Solaris Service Management Facility의 # su - postgres $ svcadm disable -s postgresql:version_82 $ svcs postgresql:version_82 STATE STIME FMRI disabled 15:11:38 svc:/application/database/postgresql:version_82 설명서
여러 매뉴얼 페이지를 통해 많은 정보를 얻을 수 있습니다. Solaris 구현에 관련된 PostgreSQL 기능을 다루는
PostgreSQL 웹 사이트에서 다음과 같은 유용한 온라인 설명서를 참조할 수 있습니다. 관리 도구 사용
GUI(그래픽 사용자 인터페이스)를 사용하려는 경우 # gunzip pgadmin3-1.6.3_x86.tar.gz # tar xf pgadmin3-1.6.3_x86.tar # pkgadd -d . pgadmin3 # /opt/bin/pgadmin3 MySQL에서 PostgreSQL로 SQL 스크립트 변환
저의 프로젝트 중 일부는 MySQL을 사용했으며 PostgreSQL을 사용할 때도 같은 기능이 필요했습니다. 아쉽게도 스크립트가 올바르게 작동하려면 약간의 수정이 필요했습니다.
요약MySQL을 간단하게 PostgreSQL로 변환할 수 있었습니다. 다음과 같은 작업은 필요하지 않았습니다.
Solaris 10 8/07 OS의 PostgreSQL 기능 및 개선 사항이 Solaris 10 릴리스의 새로운 PostgreSQL 기능 및 개선 사항의 개요는 다음과 같습니다.
추가 정보다음은 추가 리소스입니다.
Comments (latest comments first)Discuss and comment on this resource in the BigAdmin Wiki
Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License. |
BigAdmin SubscriptionsBigAdmin Areas
BigAdmin Sun Center
BigAdmin Topics | |||||||||||||||||||||||||||||||||||