postges database
postges database
SQL like子句的另一種實現方法,速度比like快
摘要:
SQL like子句的另一種實現方法,速度比like快
一般來說使用模糊查詢,大家都會想到LIKE
select * from table where a like '%字符%'
如果一個SQL語句中用多個 like模糊查詢,并且記錄條數很大,那速度一定會很慢。
下面兩種方法也可實現模糊查詢:
select * from table where patindex('%字符%',a)>0
select * from table where charindex('字符',a)>0
經測試這兩種方法比LIKE速度要快。
閱讀全文
posted @
2010-05-04 12:58 冰是沒有未來的,因為它的永恒|
編輯
pg_restore
摘要: 1.備份表中的數據
D:\Program Files\PostgreSQL-8.3.7\bin\pg_dump.exe -h *.*.*.* -p 5432 -U username -F c -v -f "D:\Program Files\PostgreSQL-8.3.7\bin\sss.backup" -t "\"public\".\"tablename\"" databasename
2. 創建表
CREATE TABLE tablename
(
id bigint,
createtime timestamp without time zone,
modifyname character varying(255),
modify_date timestamp without time zone,
modify_detail character varying(100000),
"name" character varying(255
閱讀全文
posted @
2010-03-11 10:02 冰是沒有未來的,因為它的永恒|
編輯
postgres手冊鏈接
摘要: 一.linux 監控數據庫活動
$ ps auxww | grep ^postgres
postgres 3424 0.0 1.2 42708 26588 ? Ss Jan29 0:00 postgres: writer process
postgres 3425 0.0 0.0 42576 1284 ? Ss Jan29 0:00 postgres: wal writer process
postgres 3426 0.0 0.0 43364 1972 ? Ss J
閱讀全文
posted @
2010-02-09 15:30 冰是沒有未來的,因為它的永恒|
編輯
sql 刪除重復的數據
摘要: 1、對于第一種重復,比較容易解決,使用
select distinct * from tableName
就可以得到無重復記錄的結果集。
如果該表需要刪除重復的記錄(重復記錄保留1條),可以按以下方法刪除
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
閱讀全文
posted @
2010-02-08 16:22 冰是沒有未來的,因為它的永恒|
編輯
PostgreSQL數據庫日常維護兩個要點
摘要:
數據庫服務器,應對是高并發的訪問,每天都有大量的讀寫刪除操作。因此,時間一長服務器的內存就耗盡,數據庫的占的空間也很大。為了應對這個情況,我制定兩個常用的維護操作。
一、注重日常清理(VACUUM;)。因為有大量的更新(update)"刪除(delete)操作,會有大量的空間需要釋放。
每日執行一次VACUUM,每周訪問量低的時候執行VACUUM FULL;
語法結構;
VACUUM [ FULL | FREEZE ] [ VERBOSE ] [ table ]
VACUUM [ FULL | FREEZE ] [ VERBOSE ] ANALYZE [ table [ (column [, ...] ) ] ]
FULL ------選擇"完全"清理,這樣可以恢復更多的空間, 但是花的時間更多并且在表上施加了排它鎖。
FREEZE ---------選擇激進的元組"凍結"。
VERBOSE --------- 為每個表打印一份詳細的清理工作報告。
<
閱讀全文
posted @
2010-01-07 15:55 冰是沒有未來的,因為它的永恒|
編輯
postgres create INDEX
摘要: CREATE INDEX 在指定的表上構造一個名為 index_name 的索引。索引主要用來提高數據庫性能。但是如果不恰當的使用將導致性能的下降。
PostgreSQL 為從索引提供 B-tree,R-tree,hash(散列) 和 GiST 索引方法。 B-tree 索引方法是一個 Lehman-Yao 高并發 B-trees 的實 現。R-tree 索引方法用 Guttman 的二次分裂算法實現了標準的 R-trees。 hash(散列)索引方法是 Litwin 的線性散列的一個實現。 用戶也可以定義它們自己的索引方法,但這個工作相當復雜。
如果出現了 WHERE 子句,則創建一個部分索引。 部分索引是一個只包含表的一部分記錄的索引,通常是該表中比其它部分數據更有用的部分。
在 WHERE 子句里用的表達式只能引用下層表的字段,但是它可以使用所有字段,而不僅僅是被索引的字段。 目前,子查詢和聚集表達式也不能出現在WHERE里。
索引定義里的所有函數和操作符都必須是immutable,(不
閱讀全文
posted @
2009-12-22 10:00 冰是沒有未來的,因為它的永恒|
編輯
postgres數據庫的操作
摘要: 1. 修改role密碼
alter role postgres password 'postgres';
2. 設置postgres遠程連接
1). 修改listen addresses
sudo vim /etc/postgresql/8.3/main/pg_hba.conf
# listen_addresses = 'localhost'
設置為 listen_addresses = '*'
2). 添加ip
sudo vim /etc/postgresql/8.3/main/postgresql.conf
在 最后一行添加
host all all 192.168.0.0/16 md5
3
閱讀全文
posted @
2009-07-31 14:23 冰是沒有未來的,因為它的永恒|
編輯
數據庫備份
摘要: 1.備份
>pg_dump -h 192.168.4.217 --username admin RestaurantCenter >restaurantcenter1.sql
2.執行sql
>psql -h 192.168.1.18 --username postgres RestaurantCenter < restaurantcenter1.sql
閱讀全文
posted @
2009-07-02 13:43 冰是沒有未來的,因為它的永恒|
編輯
為已經存在的數據庫添加GIS功能
摘要: PgAdmin, open up the SQL window by clicking the SQL button (the one with the pencil).
Choose “File ? Open…” and navigate to
C:\Program Files\PostgreSQL\8.3\share\contrib\lwpostgis.sql
Press the “Run” button. (The green triangle.) The lwpostgis.sql file will execute, loading the PostGIS functions and objects into the “postgis” database.
Choose “File ? Open…” and navigate to
C:\Program Files\PostgreSQL\8.3\share\contrib\spatial_ref_sys.sql
閱讀全文
posted @
2009-06-03 09:55 冰是沒有未來的,因為它的永恒|
編輯