對於我第一次嘗試使用自定義功能的PostgreSQL像first and last發生的事情好,可以被看作here恢復。PostgreSQL的,備份/自定義功能
因爲我通過.NET使用PostgreSQL我有我的功能用於備份和恢復數據庫什麼也去OK了很長的時間。現在
,當我在PostgreSQL的自定義功能,我不能存檔數據庫回來。
這裏是CMD窗口副本說的是什麼系統:
pg_restore: creating FUNCTION first_agg(anyelement, anyelement)
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 208; 1255 42417 FUNCTION first_ agg(anyelement, anyelement) postgres
pg_restore: [archiver (db)] could not execute query: ERROR: function "first_agg " already exists with same argument types
Command was: CREATE FUNCTION first_agg(anyelement, anyelement) RETURNS anyel ement
LANGUAGE sql IMMUTABLE STRICT
AS $_$ SE...
pg_restore: creating FUNCTION last_agg(anyelement, anyelement)
pg_restore: [archiver (db)] Error from TOC entry 212; 1255 42419 FUNCTION last_a gg(anyelement, anyelement) postgres
pg_restore: [archiver (db)] could not execute query: ERROR: function "last_agg"
already exists with same argument types
Command was: CREATE FUNCTION last_agg(anyelement, anyelement) RETURNS anyele ment
LANGUAGE sql IMMUTABLE STRICT
AS $_$ SEL...
pg_restore: creating AGGREGATE first(anyelement)
pg_restore: [archiver (db)] Error from TOC entry 654; 1255 42418 AGGREGATE first (anyelement) postgres
pg_restore: [archiver (db)] could not execute query: ERROR: function "first" al ready exists with same argument types
Command was: CREATE AGGREGATE first(anyelement) (
SFUNC = first_agg,
STYPE = anyelement
);
pg_restore: creating AGGREGATE last(anyelement)
pg_restore: [archiver (db)] Error from TOC entry 655; 1255 42420 AGGREGATE last( anyelement) postgres
pg_restore: [archiver (db)] could not execute query: ERROR: function "last" alr eady exists with same argument types
Command was: CREATE AGGREGATE last(anyelement) (
SFUNC = last_agg,
STYPE = anyelement
);
這是我的備份命令和恢復:
C:\Program Files (x86)\PostgreSQL\9.3\bin\pg_dump.exe" --host localhost
--port 5432 --username "postgres" --no-password --verbose -F t
--file "C:\Archives\mydatabase.tar" "mydatabase"
C:\Program Files (x86)\PostgreSQL\9.3\bin\pg_restore.exe" -i -h localhost
-p 5432 -U "postgres" -d "mydatabase" -v "C:\Archives\mydatabase.tar"
現在我沒有任何傷害,但問題是如何在涉及自定義功能時進行備份和恢復?它們也可以用數據傳輸嗎?或者必須從備份中排除?如何改進顯示的備份和恢復命令,以使這些進程順利且正常地進行?
似乎要還原備份到已包含這些功能(或不同版本的人)的數據庫。您需要在運行'pg_restore'之前刪除所有內容,或者在導入之前使用'--clean'選項刪除所有內容。順便說一句:你應該將你的函數的源代碼存儲在一個版本控制系統中(最好與Liquibase或Flyway結合起來進行適當的部署過程)。這比完成整個數據庫的備份要好得多。 –
@name,感謝您的解釋,我現在明白什麼是問題。你能給我一些鏈接到適當的部署過程嗎? –