這是歷史版本頁面 — 看 PostgreSQL (64-bit) 最新版本

PostgreSQL 是什麼,跟 MySQL 有什麼差別

PostgreSQL (64-bit) 軟體圖示 PostgreSQL (64-bit) 12.3 (64-bit) 資料更新 2020-05-22 閱讀約 7 分鐘

你正在開發一個新專案,資料量才幾萬筆,但查詢速度已經開始變慢;或者你想把分散在 Excel 和 CSV 裡的資料整理成能多人同時讀寫的格式。你打開搜尋引擎,看到一堆資料庫軟體的名字,卻不確定哪一個才適合自己——你需要的是一個能長期存放資料、支援複雜查詢、而且不會因為流量變大就垮掉的方案。

很多人第一個想到的是把資料繼續放在 Excel 或輕量型資料庫裡,但當資料量成長、需要多人同時寫入、或要做跨表格關聯查詢時,這些方案會開始卡住。這類工具的切入點是:用結構化的表格儲存資料,透過標準的 SQL 語法來查詢與管理,並提供交易保護機制,確保資料在寫入過程中不會因為意外中斷而損壞。PostgreSQL 就是這個領域裡歷史悠久、且持續在更新的開源選擇之一。

01PostgreSQL 跟 MySQL 差在哪裡?

兩者都是開源的關聯式資料庫,但 PostgreSQL 在功能上支援更多進階特性,例如自訂資料型別、部分索引、JSON/JSONB 文件儲存,以及更完整的交易隔離層級。MySQL 則以簡單易用和廣泛部署聞名。如果你的專案需要複雜查詢、地理空間資料或嚴格的資料完整性,PostgreSQL 的內建功能會更直接;若只是簡單的讀寫且團隊已熟悉 MySQL,沿用 MySQL 也能勝任。

02這套軟體能處理多大的資料量?

官方文件指出單一資料表可達 32 TB,並支援表格分割(partitioning)來分散大型資料集的儲存與查詢負擔。實際能跑多順,取決於硬體記憶體、磁碟型態和查詢語法的撰寫方式。建議先以你的真實資料量做壓力測試,確認索引和查詢計畫的執行效率,再決定是否要導入。

03它支援哪些資料型別?

涵蓋常見的整數、數值、字串、布林值、日期時間,也包含陣列、範圍、UUID、JSON/JSONB、XML、key-value(Hstore)以及幾何資料型別如點、線、圓、多邊形。此外可以自訂複合型別。這代表你不需要為了存 JSON 或座標資料另外找工具,同一套資料庫就能處理。

04要怎麼保證資料不會因為突然斷電或當機而損壞?

它實作 Write-ahead Logging(WAL),在資料真正寫入資料表前,會先把變更記錄到日誌中。若系統崩潰,重啟時會依據 WAL 進行復原,確保交易要嘛完整執行、要嘛完全沒發生。也支援同步與非同步複製,可以建立備援節點,並提供 point-in-time-recovery(PITR)把資料回復到過去某個時間點。

05多人同時讀寫同一筆資料會不會鎖住整張表?

它採用 Multi-Version Concurrency Control(MVCC),讓讀取和寫入不會互相阻擋。每個交易看到的是自己開始時的資料快照,寫入時只鎖定必要的列,而不是整張表。因此同時間大量使用者查詢、偶爾有更新時,系統仍能維持順暢。若需要更嚴格的控管,也提供明確鎖定(explicit locks)與建議鎖定(advisory locks)。

06這套軟體適合什麼樣的人用?

適合需要處理結構化資料、且查詢邏輯較複雜的開發者或資料分析師。例如要做多表關聯、子查詢、視窗函數,或需要存放 JSON 文件與地理資訊的應用。它也適合重視資料完整性與交易安全性的場景,像是金流紀錄、訂單系統。若你只是要存簡單的鍵值對,用 SQLite 或 key-value store 會更輕量。

07我完全不會寫 SQL,能用這套軟體嗎?

可以,但門檻較高。它內建的 pgAdmin 提供圖形介面,能建立資料庫、執行查詢、備份還原,不過日常操作仍需要理解基本的 SQL 語法,例如 SELECT、INSERT、UPDATE、DELETE。官方文件完整,但介面是英文。若完全不想碰 SQL,可以考慮用現成的資料庫管理工具(如 DBeaver)搭配視覺化查詢功能,但底層邏輯還是繞不開 SQL。

08什麼情況不該選 PostgreSQL?

如果你的需求只是單機應用程式暫存資料、且不想管理伺服器,SQLite 會更簡單——它不需要安裝、設定或維護,直接以檔案形式運作。若你只需要一個快速的全文字搜尋引擎,Everything Search Engine 那類工具更合適。另外,若團隊完全沒有資料庫管理經驗,且預算無法負擔專人維護,PostgreSQL 的效能調校和升級都需要手動處理,可能超出你的負荷。

09它需要多少硬體資源?

官方建議最低 2GB RAM、4GB 以上較佳,安裝本身需 100MB 以上空間,實際資料量另計。處理器需為 Intel 或 AMD 64 位元。記憶體越大,快取和排序效能越好;若同時連線數高,CPU 和記憶體需求會明顯上升。它沒有內建圖形管理介面,需額外安裝 pgAdmin 或使用命令列工具,這點在評估資源時也要算進去。

10它的授權方式會不會有商業使用的限制?

它是 Open Source 授權,可以免費使用、修改和散布,包含商業用途。沒有授權費或使用者數限制。不過要注意,它採用 PostgreSQL License,這是一種寬鬆的開源授權,允許你將它整合進商業產品中,但若你修改了原始碼並散布,需保留版權聲明。詳細條款建議閱讀官方授權文件確認。

11這套軟體多久更新一次?

根據收錄紀錄,近 12 個月更新 10 次,近 24 個月 20 次,屬於持續活躍開發的專案。官方會定期釋出主要版本和安全性修補,但升級主要版本時可能需要手動調整設定或檢查相容性。建議追蹤官方發布公告,並在測試環境先驗證再升級正式環境。

12它跟 MySQL Workbench 有什麼不同?

MySQL Workbench 是 MySQL 的圖形化管理工具,本身不是資料庫伺服器。PostgreSQL 是資料庫伺服器,官方提供的 pgAdmin 才是它的管理介面。若你習慣用 MySQL Workbench 的視覺化設計和備份功能,PostgreSQL 的 pgAdmin 也有類似功能,但介面和操作邏輯不同。兩者無法直接互換,需重新熟悉工具。

下載與官方連結

前往官方網站 下載 PostgreSQL (64-bit)

postgresql-12.3-1-windows-x64.exe · 194 MB · 連結指向軟體原廠

版本紀錄

再看 5 筆

看完整版本清單

這一版改了什麼

What's new in this version:

- Fix possible failure with GENERATED columns. If a GENERATED column's value is an exact copy of another column of the table (and it is a pass-by-reference data type), it was possible to crash or insert corrupted data into the table. While it would be rather pointless for a GENERATED expression to just duplicate another column, an expression using a function that sometimes returns its input unchanged could create the situation.
- Handle inheritance of generated columns better (Peter Eisentraut). When a table column is inherited during CREATE TABLE ... INHERITS, disallow changing any generation properties when the parent column is already marked GENERATED; but allow a child column to be marked GENERATED when its parent is not.
- Fix cross-column references in CREATE TABLE LIKE INCLUDING GENERATED (Peter Eisentraut). CREATE TABLE ... LIKE failed when trying to copy a GENERATED expression that references a physically-later column.
- Propagate ALTER TABLE ... SET STORAGE to indexes (Peter Eisentraut). Non-expression index columns have always copied the attstorage property of their table column at creation. Update them when ALTER TABLE ... SET STORAGE is done, to maintain consistency.
- Preserve the indisclustered setting of indexes rewritten by ALTER TABLE. Previously, ALTER TABLE lost track of which index had been used for CLUSTER.
- Preserve the replica identity properties of indexes rewritten by ALTER TABLE
- Preserve the indisclustered setting of indexes rebuilt by REINDEX CONCURRENTLY (Justin Pryzby)
- Lock objects sooner during DROP OWNED BY (Álvaro Herrera).This avoids failures in race-condition cases where another session is deleting some of the same objects.
- Fix error-case processing for CREATE ROLE ... IN ROLE (Andrew Gierth). Some error cases would be reported as “unexpected node type” or the like, instead of the intended message.
- Ensure that when a partition is detached, any triggers cloned from its formerly-parent table are removed
- Fix crash when COLLATE is applied to a non-collatable type in a partition bound expression (Dmitry Dolgov). Ensure that unique indexes over partitioned tables match the equality semantics of the partitioning key. This would only be an issue with index opclasses that have unusual notions of equality, but it's wrong in theory, so check.
- Ensure that members of the pg_read_all_stats role can read all statistics views, as expected (Magnus Hagander). The functions underlying the pg_stat_progress_* views had not gotten this memo.
- Repair performance regression in information_schema.triggers view (Tom Lane). This patch redefines that view so that an outer WHERE clause constraining the table name can be pushed down into the view, allowing its calculations to be done only for triggers belonging to the table of interest rather than all triggers in the database. In a database with many triggers this would make a significant speed difference for queries of that form. Since things worked that way before v11, this is a potential performance regression. Users who find this to be a problem can fix it by replacing the view definition (or, perhaps, just deleting and reinstalling the whole information_schema schema).
- Repair performance regression in floating point overflow/underflow detection. Previous refactoring had resulted in isinf() being called extra times in some hot code paths.
- Fix full text search to handle NOT above a phrase search correctly. Queries such as !(foo<->bar) failed to find matching rows when implemented as a GiST or GIN index search.
- Fix full text search for cases where a phrase search includes an item with both prefix matching and a weight restriction
- Fix ts_headline() to make better headline selections when working with phrase queries (Tom Lane)
- Fix bugs in gin_fuzzy_search_limit processing (Adé Heyward, Tom Lane). A small value of gin_fuzzy_search_limit could result in unexpected slowness due to unintentionally rescanning the same index page many times. Another code path failed to apply the intended filtering at all, possibly returning too many values.
- Allow input of type circle to accept the format “(x,y),r” as the documentation says it does (David Zhang)
- Make the get_bit() and set_bit() functions cope with bytea strings longer than 256MB (Movead Li). Since the bit number argument is only int4, it's impossible to use these functions to access bits beyond the first 256MB of a long bytea. We'll widen the argument to int8 in v13, but in the meantime, allow these functions to work on the initial substring of a long bytea.
- Ignore file-not-found errors in pg_ls_waldir() and allied functions (Tom Lane). This prevents a race condition failure if a file is removed between when we see its directory entry and when we attempt to stat() it.
- Avoid possibly leaking an open-file descriptor for a directory in pg_ls_dir(), pg_timezone_names(), pg_tablespace_databases(), and allied functions
- Fix polymorphic-function type resolution to correctly infer the actual type of an anyarray output when given only an anyrange input
- Fix server's connection-startup logic for case where a GSSAPI connection is rejected because support is not compiled in, and the client then tries SSL instead. This led to a bogus “unsupported frontend protocol” failure.
- Fix memory leakage during GSSAPI encryption (Tom Lane). Both the backend and libpq would leak memory equivalent to the total amount of data sent during the session, if GSSAPI encryption is in use.
- Fix query-lifespan memory leak for a set-returning function used in a query's FROM clause
- Avoid leakage of a hashed subplan's hash tables across multiple executions (Andreas Karlsson, Tom Lane). This mistake could result in severe memory bloat if a query re-executed a hashed subplan enough times.
- Improve planner's handling of no-op domain coercions. Fix some cases where a domain coercion that does nothing was not completely removed from expressions.
- Avoid unlikely crash when REINDEX is terminated by a session-shutdown signal
- Prevent printout of possibly-incorrect hash join table statistics in EXPLAIN
- Fix reporting of elapsed time for heap truncation steps in VACUUM VERBOSE
- Fix possible undercounting of deleted B-tree index pages in VACUUM VERBOSE output
- Fix wrong bookkeeping for oldest deleted page in a B-tree index. This could cause subtly wrong decisions about when VACUUM can skip an index cleanup scan; although it appears there may be no significant user-visible effects from that.
- Ensure that TimelineHistoryRead and TimelineHistoryWrite wait states are reported in all code paths that read or write timeline history files
- Avoid possibly showing “waiting” twice in a process's PS status
- Avoid race condition when ANALYZE replaces the catalog tuple for extended statistics data
- Remove ill-considered skip of “redundant” anti-wraparound vacuums (Michael Paquier). This avoids a corner case where autovacuum could get into a loop of repeatedly trying and then skipping the same vacuum job.
- Ensure INCLUDE'd columns are always removed from B-tree pivot tuples. This mistake wasted space in some rare cases, but was otherwise harmless.
- Cope with invalid TOAST indexes that could be left over after a failed REINDEX CONCURRENTLY
- Ensure that valid index dependencies are left behind after a failed REINDEX CONCURRENTLY (Michael Paquier). Previously the old index could be left with no pg_depend links at all, so that for example it would not get dropped if the parent table is dropped.
- Avoid failure if autovacuum tries to access a just-dropped temporary schema. This hazard only arises if a superuser manually drops a temporary schema; which isn't normal practice, but should work.
- Avoid premature recycling of WAL segments during crash recovery. WAL segments that become ready to be archived during crash recovery were potentially recycled without being archived.
- Avoid scanning irrelevant timelines during archive recovery (Kyotaro Horiguchi). This can eliminate many attempts to fetch non-existent WAL files from archive storage, which is helpful if archive access is slow.
- Remove bogus “subtransaction logged without previous top-level txn record” error check in logical decoding. This condition is legitimately reachable in various scenarios, so remove the check.
- Avoid possible failure after a replication slot copy, due to premature removal of WAL data
- Ensure that a replication slot's io_in_progress_lock is released in failure code paths. This could result in a walsender later becoming stuck waiting for the lock.
- Ensure that generated columns are correctly handled during updates issued by logical replication
- Fix race conditions in synchronous standby management. During a change in the synchronous_standby_names setting, there was a window in which wrong decisions could be made about whether it is OK to release transactions that are waiting for synchronous commit. Another hazard for similarly wrong decisions existed if a walsender process exited and was immediately replaced by another.
- Add missing SQLSTATE values to a few error reports
- Fix PL/pgSQL to reliably refuse to execute an event trigger function as a plain function
- Fix memory leak in libpq when using sslmode=verify-full. Certificate verification during connection startup could leak some memory. This would become an issue if a client process opened many database connections during its lifetime.
- Fix ecpg to treat an argument of just “-” as meaning “read from stdin” on all platforms
- Fix crash in psql when attempting to re-establish a failed connection
- Allow tab-completion of the filename argument to psql's gx command
- Add pg_dump support for ALTER ... DEPENDS ON EXTENSION. pg_dump previously ignored dependencies added this way, causing them to be forgotten during dump/restore or pg_upgrade.
- Fix pg_dump to dump comments on RLS policy objects
- In pg_dump, postpone restore of event triggers till the end. This minimizes the risk that an event trigger could interfere with the restoration of other objects.
- Ensure that pg_basebackup generates valid tar files. In some cases a partial block of zeroes would be added to the end of the file. While this seems to be harmless with common versions of tar, it's not OK per the POSIX file format spec.
- Make pg_checksums skip tablespace subdirectories that belong to a different PostgreSQL major version. Such subdirectories don't really belong to our database cluster, and so must not be processed.
- Ignore temporary copies of pg_internal.init in pg_checksums and related programs (Michael Paquier)
- Fix quoting of --encoding, --lc-ctype and --lc-collate values in createdb utility (Michael Paquier)
- contrib/lo's lo_manage() function crashed if called directly rather than as a trigger (Tom Lane)
- In contrib/ltree, protect against overflow of ltree and lquery length fields (Nikita Glukhov)
- Work around failure in contrib/pageinspect's bt_metap() function when an oldest_xact value exceeds 2^31-1 (Peter Geoghegan). Such XIDs will now be reported as negative integers, which isn't great but it beats throwing an error. v13 will widen the output argument to int8 to provide saner reporting.
- Fix cache reference leak in contrib/sepgsql
- On Windows, avoid premature creation of postmaster's log file during pg_ctl start. The previous coding could allow the file to be created with permissions that wouldn't allow the postmaster to write on it.
- Avoid failures when dealing with Unix-style locale names on Windows
- On Windows, set console VT100 compatibility mode in programs that support PG_COLOR colorization. Without this, the colorization option doesn't actually work.
- Stop requiring extra parentheses in ereport() calls
- Use pkg-config, if available, to locate libxml2 during configure. If pkg-config is not present or lacks knowledge of libxml2, we still query xml2-config as before. This change could break build processes that try to make PostgreSQL use a non-default version of libxml2 by putting that version's xml2-config into the PATH. Instead, set XML2_CONFIG to point to the non-default xml2-config. That method will work with either older or newer PostgreSQL releases.
- Fix Makefile dependencies for libpq and ecpg
- In MSVC builds, cope with spaces in the path name for Python
- In MSVC builds, fix detection of Visual Studio version to work with more language settings
- In MSVC builds, use -Wno-deprecated with bison versions newer than 3.0, as non-Windows builds already do. Update time zone data files to tzdata release 2020a for DST law changes in Morocco and the Canadian Yukon, plus historical corrections for Shanghai. The America/Godthab zone has been renamed to America/Nuuk to reflect current English usage; however, the old name remains available as a compatibility link. Also, update initdb's list of known Windows time zone names to include recent additions, improving the odds that it will correctly translate the system time zone setting on that platform.