Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to retrieve system columns such as xmin and ctid #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contrib/pg_dirtyread/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
regression.diffs
regression.out
results/
*.o
*.so
48 changes: 48 additions & 0 deletions contrib/pg_dirtyread/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# run the testsuite on travis-ci.com
---
# versions to run on
env:
- PG_SUPPORTED_VERSIONS=9.2
- PG_SUPPORTED_VERSIONS=9.3
- PG_SUPPORTED_VERSIONS=9.4
- PG_SUPPORTED_VERSIONS=9.5
- PG_SUPPORTED_VERSIONS=9.6
- PG_SUPPORTED_VERSIONS=10

language: C
dist: trusty
sudo: required

before_install:
# apt.postgresql.org is already configured, we just need to add devel
- |
DIST=trusty-pgdg
if [ "$PG_SUPPORTED_VERSIONS" = "10" ]; then
# update pgdg-source.list
sudo sed -i -e "s/pgdg.*/pgdg-testing main $PG_SUPPORTED_VERSIONS/" /etc/apt/sources.list.d/pgdg*.list
DIST=trusty-pgdg-testing
fi
- sudo apt-get -qq update

install:
- export DEBIAN_FRONTEND=noninteractive # suppress warnings about deprecated PostgreSQL versions
# trusty's pg_buildext doesn't cope with PG version numbers >= 10, so upgrade that to -pgdg
- sudo apt-get install debhelper devscripts fakeroot postgresql-server-dev-$PG_SUPPORTED_VERSIONS postgresql-server-dev-all/$DIST
# install PostgreSQL $PG_SUPPORTED_VERSIONS if not there yet
- |
if [ ! -x /usr/lib/postgresql/$PG_SUPPORTED_VERSIONS/bin/postgres ]; then
sudo apt-get install postgresql-common # upgrade pg-common first ...
sudo /etc/init.d/postgresql stop # ... so we can stop postgresql again before installing the server
sudo apt-get install postgresql-$PG_SUPPORTED_VERSIONS
fi
# stop the travis-provided cluster
- sudo /etc/init.d/postgresql stop
- pg_lsclusters
- dpkg -l postgresql\* | cat

script:
- pg_buildext updatecontrol
- dpkg-buildpackage -us -uc -rfakeroot
- for deb in ../*.deb; do echo "$deb:"; dpkg-deb --info $deb; dpkg-deb --contents $deb; done
- sudo debi
- pg_buildext -i '--locale=C.UTF-8' installcheck
32 changes: 32 additions & 0 deletions contrib/pg_dirtyread/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Copyright (c) 1996-2017, PostgreSQL Global Development Group
Copyright (c) 2012, OmniTI Computer Consulting, Inc.
Portions Copyright (c) 1994, The Regents of the University of California

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name OmniTI Computer Consulting, Inc. nor the names
of its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7 changes: 6 additions & 1 deletion contrib/pg_dirtyread/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
MODULES = pg_dirtyread
MODULE_big = pg_dirtyread
OBJS = pg_dirtyread.o dirtyread_tupconvert.o

EXTENSION = pg_dirtyread
DATA = pg_dirtyread--1.0.sql

REGRESS = extension dirtyread

PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

pg_dirtyread.o dirtyread_tupconvert.o: dirtyread_tupconvert.h
95 changes: 90 additions & 5 deletions contrib/pg_dirtyread/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pg_dirtyread 1.0
================
pg_dirtyread
============

The pg_dirtyread extension provides the ability to read dead but unvacuumed
rows from a relation.
Expand All @@ -23,18 +23,103 @@ to find it:

env PG_CONFIG=/path/to/pg_config make && make install

Loading
Loading and Using
-------

Once pg_dirtyread is built and installed, you can add it to a database. Loading
pg_dirtyread is as simple as connecting to a database as a super user and
running:

```sql
CREATE EXTENSION pg_dirtyread;
SELECT * FROM pg_dirtyread('tablename'::regclass) AS t(col1 type1, col2 type2, ...);
```

Using
-----
The `pg_dirtyread()` function returns RECORD, therefore it is necessary to
attach a table alias clause that describes the table schema. Columns are
matched by name, so it is possible to omit some columns in the alias, or
rearrange columns.

Example:

```sql
CREATE EXTENSION pg_dirtyread;

-- Create table and disable autovacuum
CREATE TABLE foo (bar bigint, baz text);
ALTER TABLE foo SET (
autovacuum_enabled = false, toast.autovacuum_enabled = false
);

INSERT INTO foo VALUES (1, 'Test'), (2, 'New Test');
DELETE FROM foo WHERE bar = 1;

SELECT * FROM pg_dirtyread('foo'::regclass) as t(bar bigint, baz text);
```

Where the schema of `foo` is `(bar bigint, baz text)`.

System Columns
--------------

System columns such as `xmax` and `ctid` can be retrieved by including them in
the table alias attached to the `pg_dirtyread()` call. A special column `dead` of
type boolean is available to report dead rows (as by `HeapTupleIsSurelyDead`).
The `dead` column is not usable during recovery, i.e. most notably not on
standby servers.

```sql
SELECT * FROM pg_dirtyread('foo'::regclass)
AS t(tableoid oid, ctid tid, xmin xid, xmax xid, cmin cid, cmax cid, dead boolean,
oid oid, bar bigint, baz text);
tableoid │ ctid │ xmin │ xmax │ cmin │ cmax │ dead │ oid │ bar │ baz
──────────┼───────┼──────┼──────┼──────┼──────┼──────┼─────┼─────┼───────────────────
41823 │ (0,1) │ 1484 │ 1485 │ 0 │ 0 │ t │ 0 │ 1 │ Delete
41823 │ (0,2) │ 1484 │ 0 │ 0 │ 0 │ f │ 0 │ 2 │ Insert
41823 │ (0,3) │ 1484 │ 1486 │ 0 │ 0 │ t │ 0 │ 3 │ Update
41823 │ (0,4) │ 1484 │ 1488 │ 0 │ 0 │ f │ 0 │ 4 │ Not deleted
41823 │ (0,5) │ 1484 │ 1489 │ 1 │ 1 │ f │ 0 │ 5 │ Not updated
41823 │ (0,6) │ 1486 │ 0 │ 0 │ 0 │ f │ 0 │ 3 │ Updated
41823 │ (0,7) │ 1489 │ 0 │ 1 │ 1 │ t │ 0 │ 5 │ Not quite updated
41823 │ (0,8) │ 1490 │ 0 │ 2 │ 2 │ t │ 0 │ 6 │ Not inserted
```

License
-------

Original author: Phil Sorber

Copyright (c) 1996-2017, PostgreSQL Global Development Group

Copyright (c) 2012, OmniTI Computer Consulting, Inc.

Portions Copyright (c) 1994, The Regents of the University of California

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name OmniTI Computer Consulting, Inc. nor the names
of its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading