一
RedHat Enterprise Linux
Windows XP SP
PostgreSQL
Eclipse+Pydev+python
a
b
二
E:\Program Files\PostgreSQL\
E:\Program Files\PostgreSQL\
a
b
《RedHat Linux上安装PostgreSQL》
《PostgreSQL服务端监听设置及客户端连接方法》
《PostgreSQL数据库创建
三
[python] view plaincopyprint?
#!/usr/bin/env python
#
#导入日志及pg模块
import logging
import nfig
import pg
#日志配置文件名
LOG_FILENAME =
#日志语句提示信息
LOG_CONTENT_NAME =
def log_init(log_config_filename
Function:日志模块初始化函数
Input
lognmae:每条日志前的提示语句
Output: logger
author: socrates
date:
nfig
logger = logging
return logger
def operate_postgre_tbl_product():
Function:操作pg数据库函数
Input
Output: NONE
author: socrates
date:
pgdb_logger
#连接数据库
try:
pgdb_conn = nnect(dbname =
except Exception
print e
pgdb_logger
return
(
#删除表
sql_desc =
try:
pgdb_conn
except Exception
print
pgdb_logger
pgdb_conn
return
(
#创建表
sql_desc =
i_index INTEGER
sv_productname VARCHAR(
);
try:
pgdb_conn
except Exception
print
pgdb_logger
pgdb_conn
return
(
#插入记录
sql_desc =
try:
pgdb_conn
except Exception
print
pgdb_logger
pgdb_conn
return
(
#查询表
sql_desc =
for row in pgdb_conn
print row
(
#查询表
sql_desc =
for row in pgdb_conn
print row
(
#关闭数据库连接
pgdb_conn
pgdb_logger
if __name__ ==
#初始化日志系统
pgdb_logger = log_init(LOG_FILENAME
#操作数据库
operate_postgre_tbl_product()
[plain] view plaincopyprint?
{
{
{
{
{
{
{
{
{
{
{
{
{
[plain] view plaincopyprint?
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[plain] view plaincopyprint?
[root@kevin ~]# su
[postgres@kevin ~]$ psql
psql (
Type
kevin_test=# \dt
List of relations
Schema | Name | Type | Owner
public | tbl_product
public | tbl_test_port | table | pg_test_user_
(
kevin_test=# select * from tbl_product
i_index | sv_productname
| apple
(
kevin_test=# select * from tbl_test_port;
i_index | i_port | i_status
(
kevin_test=# \q
[postgres@kevin ~]$