AVAYA AEP运维之PostgreSQL数据库相关

发布时间:2020-06-12 16:15:05 作者:cuihuayu
来源:网络 阅读:679

   由于AEP EPM所有相关的报表数据(应用运行日志,呼叫清单,会话清单),配置信息等都存在本地PostgreSQL上,了解PostgreSQL的相关基本使用方法,有助于日常运维能力的提升。本篇主要总结如何开启本地登陆,开启远端登陆,基本命令,数据备份和清理。

在EPM安装的过程中,会把PostgreSQL也一并安装掉,过程中会提示输入用户名postgres的密码,以及创建一个报表用户。当时当你本地使用PostgreSQL去登陆数据库时,始终登陆不上;通过PostgreSQL客户端也始终登陆不上,需要进行如下操作来开启本地和远端登陆。

[root@vp142 VP-Tools]# su - postgres
-bash-4.1$ ls
9.0  data  pgstartup.log  SQLscripts
-bash-4.1$ cd data/
-bash-4.1$ vi pg_hba.conf  //找到如下部分,修改第一条记录(运行本地登陆)以及新增一条记录(运行远端登陆,记得先备份该配置文件)

AVAYA AEP运维之PostgreSQL数据库相关

改完后:wq保存,然后重启PostgreSQL服务。

-bash-4.1$ exit
logout
[root@vp142 VP-Tools]# service postgresql restart


[root@vp142 VP-Tools]# psql -h 127.0.0.1 -U postgres -d VoicePortal
Password for user postgres: 
psql (9.0.15)
Type "help" for help.

VoicePortal=# //本地登陆成功

 远端登陆:下载PostgreSQL客户端,配置

AVAYA AEP运维之PostgreSQL数据库相关

登陆成功:

AVAYA AEP运维之PostgreSQL数据库相关

VoicePortal-# \l    //输出所有数据库
                                   List of databases
    Name     |  Owner   | Encoding |  Collation  |    Ctype    |   Access privil
eges   
-------------+----------+----------+-------------+-------------+----------------
-------
 VoicePortal | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres    
 VoicePortal-# \c postgres  //切换到postgres库
You are now connected to database "postgres". 
postgres-# 
VoicePortal-# \d   //显示当前库有哪些表
                      List of relations
 Schema |             Name              |   Type   |  Owner   
--------+-------------------------------+----------+----------
 public | alarmcode                     | table    | postgres
 public | alarmcodelistenerlink         | table    | postgres
 public | alarmcodelistenerlinkdefault  | table    | postgres
 public | alarmhistory                  | table    | postgres
 public | alarmlistener                 | table    | postgres
 public | alarmnotify                   | table    | postgres
 。。。。。。
 VoicePortal-# \d cdr   //查看cdr表的结构
                                            Table "public.cdr"
       Column       |            Type             |                       Modifi
ers                        
--------------------+-----------------------------+-----------------------------
---------------------------
 calltimestamp      | timestamp without time zone | 
 recordid           | integer                     | 
 sessionid          | character varying           | 
 callid             | character varying           | 
 ucid               | character varying           | 
 portid             | integer                     | 
 
 创建数据库: 
create database [数据库名]; 
删除数据库: 
drop database [数据库名];  
*重命名一个表: 
alter table [表名A] rename to [表名B]; 
*删除一个表: 
drop table [表名]; 
*在已有的表里添加字段: 
alter table [表名] add column [字段名] [类型]; 
*删除表中的字段: 
alter table [表名] drop column [字段名]; 
*重命名一个字段:  
alter table [表名] rename column [字段名A] to [字段名B]; 
*给一个字段设置缺省值:  
alter table [表名] alter column [字段名] set default [新的默认值];
*去除缺省值:  
alter table [表名] alter column [字段名] drop default; 
在表中插入数据: 
insert into 表名 ([字段名m],[字段名n],......) values ([列m的值],[列n的值],......); 
修改表中的某行某列的数据: 
update [表名] set [目标字段名]=[目标值] where [该行特征]; 
删除表中某行数据: 
delete from [表名] where [该行特征]; 
delete from [表名];--删空整个表 
创建表: 
create table ([字段名1] [类型1] ;,[字段名2] [类型2],......<,primary key (字段名m,字段名n,...)>;); 
\copyright     显示 PostgreSQL 的使用和发行条款
\encoding [字元编码名称]
                 显示或设定用户端字元编码
\h [名称]      SQL 命令语法上的说明,用 * 显示全部命令
\prompt [文本] 名称
                 提示用户设定内部变数
\password [USERNAME]
                 securely change the password for a user
\q             退出 psql


PostgreSQL数据备份:
[root@vp142 VP-Tools]# pg_dump -U postgres VoicePortal >/cpic/craft/postgresdata
.20160425.sql
Password:    //输入完密码后,等待备份完毕。
[root@vp142 VP-Tools]# ll /cpic/craft/postgresdata.20160425.sql //查看备份文件
-rw-r--r-- 1 root root 4007564 Apr 25 16:57 /cpic/craft/postgresdata.20160425.sql

PostgreSQL数据恢复:
先清空数据库(该脚本清空相关报表数据,并非系统重要配置信息):
[root@vp142 VP-Tools]# bash PurgeReportDataLocalDB 

Do you wish to purge all your report data?

Press enter to continue, or press control-C to abort this utility

Purging SDR table...
Purging CDR table...
Purging VPAppLog table...
Purging VPPerformance table...
Purging completed!
-----------------------------------------------------
开始恢复数据:
[root@vp142 VP-Tools]# psql -U postgres VoicePortal < /cpic/craft/postgresdata.20160425.sql
Password for user postgres: 
 lowrite 
---------
     535
(1 row)

 lo_close 
----------
        0
(1 row)

COMMIT
。。。。。。


推荐阅读:
  1. sql查询语句的使用示例
  2. SQL中EXPLAIN命令怎么用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

sql 数据备份 postgresql

上一篇:​mock JQuery的基本使用

下一篇:rman 脚本

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》