我有一個 shell 腳本將資料從服務器提取到 postgresql 表中。
df -g | awk 'BEGIN{OFS=","}NR>1{$1=$1; print}' > /data/metric.csv
psql -h localhost -d metrics -U postgres -c "copy tablename from STDIN with delimiter as ',';" < /data/metric.csv
顯示為:
filesystem | gb_blocks | free | %used | iused | %iused | mounted_on
/dev/hd2 | 16.75 | 12.60 | 25% | 79098 | 3% | /usr
/dev/hd9var | 8.00 | 6.00 | 25% | 11965 | 1% | /var
/dev/hd3 | 36.75 | 18.83 | 49% | 5614 | 1% | /tmp
/dev/hd1 | 3.25 | 3.11 | 5% | 674 | 1% | /home
/dev/hd11admin | 0.25 | 0.25 | 1% | 16 | 1% | /admin
/proc | - | - | - | - | - | /proc
我正在 Ubuntu 作業系統上使用 Postgresql 并從 AIX 服務器中提取資訊。我想為每次將新資料添加到表中時添加一個帶有時間戳的列,因為現在它只是混合在一起。我試圖為時間戳添加另一列并為其提供時間戳值,但時間戳不在 csv 檔案中,我也不知道如何添加它。我很感激我能得到的幫助來解決這個問題。
uj5u.com熱心網友回復:
創建表并添加日期列,其Default值為current_Date/now() ).
CREATE TABLE IF NOT EXISTS metrics
(
filesystem text ,
gb_blocks text ,
free text ,
per_used text ,
iused text ,
per_iused text ,
mounted_on text ,
load_dttm timestamp without time zone DEFAULT now()
);
columns加載資料時用表提及,如下命令
psql -h localhost -d metrics -U postgres -c "copy metrics(filesystem,gb_blocks,free,per_used,iused,per_iused,mounted_on) from STDIN with delimiter as ',';" < /data/metric.csv
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/403376.html
標籤:
