Skip to content

Commit

Permalink
Add pg_list_relation_filepath().
Browse files Browse the repository at this point in the history
This function lists the file path names of the specified relation.
  • Loading branch information
MasaoFujii committed Feb 20, 2020
1 parent b00b696 commit a580b6a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ Return the Process ID of the postmaster process.
Return the time when the server process attached to the current session
was started.

### SETOF text pg_list_relation_filepath(relation regclass)
List the file path names of the specified relation.
Note that this function returns only the path name of
the first segment file in PostgreSQL 9.4 or before.

### text pg_tablespace_version_direcotry()
Return the name of major-version-specific tablespace subdirectory.

Expand Down
22 changes: 22 additions & 0 deletions pg_cheat_funcs--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,28 @@ RETURNS timestamptz
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT STABLE;

CREATE FUNCTION pg_list_relation_filepath(relation regclass)
RETURNS SETOF text AS $$
DECLARE
segcount bigint := 1;
relationpath text;
pathname text;
BEGIN
relationpath := pg_relation_filepath(relation);
RETURN NEXT relationpath;
IF current_setting('server_version_num')::integer < 90500 THEN
RETURN;
END IF;
LOOP
pathname := relationpath || '.' || segcount;
EXIT WHEN pg_stat_file(pathname, true) IS NULL;
RETURN NEXT pathname;
segcount := segcount + 1;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql STRICT VOLATILE;

CREATE FUNCTION pg_tablespace_version_directory()
RETURNS text
AS 'MODULE_PATHNAME'
Expand Down

0 comments on commit a580b6a

Please sign in to comment.