您好,登錄后才能下訂單哦!
由于AEP EPM所有相關(guān)的報(bào)表數(shù)據(jù)(應(yīng)用運(yùn)行日志,呼叫清單,會話清單),配置信息等都存在本地PostgreSQL上,了解PostgreSQL的相關(guān)基本使用方法,有助于日常運(yùn)維能力的提升。本篇主要總結(jié)如何開啟本地登陸,開啟遠(yuǎn)端登陸,基本命令,數(shù)據(jù)備份和清理。
如何開啟本地和遠(yuǎn)端登陸
在EPM安裝的過程中,會把PostgreSQL也一并安裝掉,過程中會提示輸入用戶名postgres的密碼,以及創(chuàng)建一個(gè)報(bào)表用戶。當(dāng)時(shí)當(dāng)你本地使用PostgreSQL去登陸數(shù)據(jù)庫時(shí),始終登陸不上;通過PostgreSQL客戶端也始終登陸不上,需要進(jìn)行如下操作來開啟本地和遠(yuǎn)端登陸。
[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 //找到如下部分,修改第一條記錄(運(yùn)行本地登陸)以及新增一條記錄(運(yùn)行遠(yuǎn)端登陸,記得先備份該配置文件)
改完后:wq保存,然后重啟PostgreSQL服務(wù)。
-bash-4.1$ exit logout [root@vp142 VP-Tools]# service postgresql restart
本地和遠(yuǎn)端登陸驗(yàn)證
[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=# //本地登陸成功
遠(yuǎn)端登陸:下載PostgreSQL客戶端,配置
登陸成功:
PostgreSQL 常用命令
VoicePortal-# \l //輸出所有數(shù)據(jù)庫 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 //顯示當(dāng)前庫有哪些表 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表的結(jié)構(gòu) 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 | 創(chuàng)建數(shù)據(jù)庫: create database [數(shù)據(jù)庫名]; 刪除數(shù)據(jù)庫: drop database [數(shù)據(jù)庫名]; *重命名一個(gè)表: alter table [表名A] rename to [表名B]; *刪除一個(gè)表: drop table [表名]; *在已有的表里添加字段: alter table [表名] add column [字段名] [類型]; *刪除表中的字段: alter table [表名] drop column [字段名]; *重命名一個(gè)字段: alter table [表名] rename column [字段名A] to [字段名B]; *給一個(gè)字段設(shè)置缺省值: alter table [表名] alter column [字段名] set default [新的默認(rèn)值]; *去除缺省值: alter table [表名] alter column [字段名] drop default; 在表中插入數(shù)據(jù): insert into 表名 ([字段名m],[字段名n],......) values ([列m的值],[列n的值],......); 修改表中的某行某列的數(shù)據(jù): update [表名] set [目標(biāo)字段名]=[目標(biāo)值] where [該行特征]; 刪除表中某行數(shù)據(jù): delete from [表名] where [該行特征]; delete from [表名];--刪空整個(gè)表 創(chuàng)建表: create table ([字段名1] [類型1] ;,[字段名2] [類型2],......<,primary key (字段名m,字段名n,...)>;); \copyright 顯示 PostgreSQL 的使用和發(fā)行條款 \encoding [字元編碼名稱] 顯示或設(shè)定用戶端字元編碼 \h [名稱] SQL 命令語法上的說明,用 * 顯示全部命令 \prompt [文本] 名稱 提示用戶設(shè)定內(nèi)部變數(shù) \password [USERNAME] securely change the password for a user \q 退出 psql
數(shù)據(jù)庫備份與恢復(fù)
PostgreSQL數(shù)據(jù)備份: [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數(shù)據(jù)恢復(fù): 先清空數(shù)據(jù)庫(該腳本清空相關(guān)報(bào)表數(shù)據(jù),并非系統(tǒng)重要配置信息): [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! ----------------------------------------------------- 開始恢復(fù)數(shù)據(jù): [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 。。。。。。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。