Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Rename extension to amcheck_next
Browse files Browse the repository at this point in the history
amcheck_next is a distinct extension to contrib/amcheck for PostgreSQL
extension purposes.  It has non-conflicting symbol names.  This is
preparation for Debian PGDG apt packaging.

This establishes the convention that extension version will not be equal
to package/release version, in order to ease shipping new versions that
only change C code (versions that require no SQL script changes).  We
now follow the style of postgresql-unit: we use simple integers for SQL
extension versions, but traditional mulipart versions for packages.
This convention is intended to make it clear that SQL extension version
and package version are orthogonal.

The first SQL extension version is 1.  The package version is 1.0.

In passing, Change Debian debian/source/format to "1.0", and remove
Travis support.

Per feedback from Christoph Berg.
  • Loading branch information
petergeoghegan committed Oct 7, 2017
1 parent 0b236ae commit 1a7685a
Show file tree
Hide file tree
Showing 25 changed files with 229 additions and 329 deletions.
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
short_ver = 0.3
short_ver = 1
long_ver = $(shell (git describe --tags --long '--match=v*' 2>/dev/null || echo $(short_ver)-0-unknown) | cut -c2-)

MODULE_big = amcheck
MODULE_big = amcheck_next
OBJS = verify_nbtree.o $(WIN32RES)

EXTENSION = amcheck
DATA = amcheck--0.3.sql
PGFILEDESC = "amcheck - function for verifying relation integrity"
EXTENSION = amcheck_next
DATA = amcheck_next--1.sql
PGFILEDESC = "amcheck_next - functions for verifying relation integrity"
DOCS = README.md
REGRESS = install_amcheck extern_sort_bytea \
extern_sort_collations extern_sort_numeric
REGRESS = install_amcheck_next check_btree

PG_CONFIG = pg_config
PGXS = $(shell $(PG_CONFIG) --pgxs)
Expand All @@ -22,4 +21,4 @@ deb:
rsync -Ca --exclude=build/* ./ $(DEBUILD_ROOT)/
cd $(DEBUILD_ROOT) && make -f debian/rules orig
cd $(DEBUILD_ROOT) && debuild -us -uc -sa
cp -a /tmp/amcheck_* /tmp/postgresql-9.* build/
cp -a /tmp/amcheck_* /tmp/postgresql-[91]* build/
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# amcheck: Verify the logical consistency of PostgreSQL B-Tree indexes

Current version: 0.3
Current version: 1.0 (`amcheck_next` extension/SQL version: 1)

Author: Peter Geoghegan [`<pg@bowt.ie>`](mailto:pg@bowt.ie)

Expand All @@ -20,6 +20,14 @@ in production PostgreSQL installations.
See "Using amcheck effectively" below for information about the kinds of
real-world problems `amcheck` is intended to detect.

### Project background

`amcheck` is a contrib extension for PostgreSQL 10+. This externally
maintained version of the extension, `amcheck_next`, exists to target earlier
versions of PostgreSQL, and to provide extended verification functionality to
older PostgreSQL versions. It is safe (though generally not useful) to install
`amcheck_next` alongside `contrib/amcheck`.

### Invariants

`amcheck` provides functions that specifically verify various *invariants* in
Expand All @@ -41,11 +49,6 @@ to guide the scan to a point in the underlying table; see
http://www.postgresql.org/docs/current/static/xindex.html for details of
operator class support functions.

### Project background

`amcheck` is a contrib extension for PostgreSQL 10. This externally maintained
version of the extension exists to target earlier versions of PostgreSQL.

### Bugs

Report bugs using the <a
Expand All @@ -63,8 +66,8 @@ If you are using a packaged PostgreSQL build and have `pg_config` available
(and in your OS user's $PATH), the procedure is as follows:

```shell
tar xvzf amcheck-0.3.tar.gz
cd amcheck-0.3
tar xvzf amcheck-1.0.tar.gz
cd amcheck-1.0
make
make install
```
Expand All @@ -89,19 +92,22 @@ sudo dpkg -i ./build/postgresql-9.4-amcheck_*.deb

### Setting up PostgreSQL

Once `amcheck` is built and installed, it should be created as a PostgreSQL
Once the module is built and installed, it should be created as a PostgreSQL
extension in every database that requires it:

`mydb=# CREATE EXTENSION amcheck;`
`mydb=# CREATE EXTENSION amcheck_next;`

`amcheck` functions may be used only by superusers.

Note that the extension is named `amcheck_next` in order to distinguish it from
the PostgreSQL contrib extension `amcheck`.

## Interface

The `amcheck` extension has a simple interface. `amcheck` consists of just a
few functions that can be used for verification of a named B-Tree index. Note
that currently, no function inspects the structure of the underlying heap
representation (table).
The `amcheck_next` extension has a simple interface. `amcheck_next` consists
of just a few functions that can be used for verification of a named B-Tree
index. Note that currently, no function inspects the structure of the
underlying heap representation (table).

`regclass` function arguments are used by `amcheck` to identify particular
index relations. This allows `amcheck` to accept arguments using various
Expand Down Expand Up @@ -154,14 +160,13 @@ invariants. Example usage:
| pg_amop_fam_strat_index | 5
```

This example shows a session that performs verification of every catalog index
in the database. Details of just the 10 largest indexes verified are
displayed. Since no error is raised, all indexes tested appear to be logically
consistent. Naturally, this query could easily be changed to call
`bt_index_check` for every index in the database where verification is
supported. An `AccessShareLock` is acquired on the target index by
`bt_index_check`. This lock mode is the same lock mode acquired on relations
by simple `SELECT` statements.
This example shows a session that performs verification of catalog indexes.
Since no error is raised, all indexes tested appear to be logically consistent.
Naturally, this query could easily be changed to call `bt_index_check` for
every index in the database where verification is supported. An
`AccessShareLock` is acquired on the target index by `bt_index_check`. This
lock mode is the same lock mode acquired on relations by simple `SELECT`
statements.

`bt_index_check` does not verify invariants that span child/parent
relationships, nor does it verify that the target index is consistent with its
Expand Down
12 changes: 0 additions & 12 deletions amcheck--0.1--0.3.sql

This file was deleted.

12 changes: 0 additions & 12 deletions amcheck--0.2--0.3.sql

This file was deleted.

5 changes: 0 additions & 5 deletions amcheck.control

This file was deleted.

8 changes: 4 additions & 4 deletions amcheck--0.3.sql → amcheck_next--1.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/* amcheck--0.3.sql */
/* amcheck_next--1.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION amcheck" to load this file. \quit
\echo Use "CREATE EXTENSION amcheck_next" to load this file. \quit

--
-- bt_index_check()
--
CREATE FUNCTION bt_index_check(index regclass)
RETURNS VOID
AS 'MODULE_PATHNAME', 'bt_index_check'
AS 'MODULE_PATHNAME', 'bt_index_check_next'
LANGUAGE C STRICT;

--
-- bt_index_parent_check()
--
CREATE FUNCTION bt_index_parent_check(index regclass)
RETURNS VOID
AS 'MODULE_PATHNAME', 'bt_index_parent_check'
AS 'MODULE_PATHNAME', 'bt_index_parent_check_next'
LANGUAGE C STRICT;

-- Don't want these to be available to public
Expand Down
5 changes: 5 additions & 0 deletions amcheck_next.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# amcheck_next extension
comment = 'verify the logical consistency of indexes'
default_version = '1'
module_pathname = '$libdir/amcheck_next'
relocatable = true
17 changes: 16 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
amcheck (1.0-1) stable; urgency=medium

* Correct 0.3-1 date string in changelog

* Normalize copyright assignment, and make debian copyright file consistent
with LICENSE.md

* Create extension with the name amcheck_next, to avoid ambiguity.

* Remove Travis support.

* Replace tests with upstream contrib/amcheck tests.

-- Peter Geoghegan <pg@bowt.ie> Sat, 07 Oct 2017 09:28:38 -0700

amcheck (0.3-1) unstable; urgency=low

* Tweaks to some diagnostic messages

* Detect disagreement between parent/child B-Tree level

-- Peter Geoghegan <pg@bowt.ie> Fri, 16 June 2017 17:31:41 -0700
-- Peter Geoghegan <pg@bowt.ie> Fri, 16 Jun 2017 17:31:41 -0700

amcheck (0.2-1) unstable; urgency=low

Expand Down
9 changes: 9 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ Description: PostgreSQL extension that verifies indexes
during a call to these verification functions, no logical inconsistency was
detected. This is useful as a general smoke test to detect corruption.

Package: postgresql-10-amcheck
Section: libs
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, postgresql-10
Description: PostgreSQL extension that verifies indexes
This extension verifies the logical consistency of PostgreSQL B-Tree indexes.
The extension consists of SQL-callable functions. When no error is raised
during a call to these verification functions, no logical inconsistency was
detected. This is useful as a general smoke test to detect corruption.
3 changes: 1 addition & 2 deletions debian/pgversions
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Only support versions with robust approach to B-Tree page deletion and
# concurrent page splits
#
# PostgreSQL 10 is not supported, if only because its contrib extension has a conflicting extension name.
9.4
9.5
9.6
10
2 changes: 1 addition & 1 deletion debian/source/format
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0 (quilt)
1.0
85 changes: 85 additions & 0 deletions expected/check_btree.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
-- minimal test, basically just verifying that amcheck
CREATE TABLE bttest_a(id int8);
CREATE TABLE bttest_b(id int8);
INSERT INTO bttest_a SELECT * FROM generate_series(1, 100000);
INSERT INTO bttest_b SELECT * FROM generate_series(100000, 1, -1);
CREATE INDEX bttest_a_idx ON bttest_a USING btree (id);
CREATE INDEX bttest_b_idx ON bttest_b USING btree (id);
CREATE ROLE bttest_role;
-- verify permissions are checked (error due to function not callable)
SET ROLE bttest_role;
SELECT bt_index_check('bttest_a_idx'::regclass);
ERROR: permission denied for function bt_index_check
SELECT bt_index_parent_check('bttest_a_idx'::regclass);
ERROR: permission denied for function bt_index_parent_check
RESET ROLE;
-- we, intentionally, don't check relation permissions - it's useful
-- to run this cluster-wide with a restricted account, and as tested
-- above explicit permission has to be granted for that.
GRANT EXECUTE ON FUNCTION bt_index_check(regclass) TO bttest_role;
GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass) TO bttest_role;
SET ROLE bttest_role;
SELECT bt_index_check('bttest_a_idx');
bt_index_check
----------------

(1 row)

SELECT bt_index_parent_check('bttest_a_idx');
bt_index_parent_check
-----------------------

(1 row)

RESET ROLE;
-- verify plain tables are rejected (error)
SELECT bt_index_check('bttest_a');
ERROR: "bttest_a" is not an index
SELECT bt_index_parent_check('bttest_a');
ERROR: "bttest_a" is not an index
-- verify non-existing indexes are rejected (error)
SELECT bt_index_check(17);
ERROR: could not open relation with OID 17
SELECT bt_index_parent_check(17);
ERROR: could not open relation with OID 17
-- normal check outside of xact
SELECT bt_index_check('bttest_a_idx');
bt_index_check
----------------

(1 row)

-- more expansive test
SELECT bt_index_parent_check('bttest_b_idx');
bt_index_parent_check
-----------------------

(1 row)

BEGIN;
SELECT bt_index_check('bttest_a_idx');
bt_index_check
----------------

(1 row)

SELECT bt_index_parent_check('bttest_b_idx');
bt_index_parent_check
-----------------------

(1 row)

-- make sure we don't have any leftover locks
SELECT * FROM pg_locks
WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[])
AND pid = pg_backend_pid();
locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath
----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-----+------+---------+----------
(0 rows)

COMMIT;
-- cleanup
DROP TABLE bttest_a;
DROP TABLE bttest_b;
DROP OWNED BY bttest_role; -- permissions
DROP ROLE bttest_role;
Loading

0 comments on commit 1a7685a

Please sign in to comment.