path ~ ('PG_' || substring(current_setting('server_version') FROM '^(?:\d.\d\d?|\d+)'))
When you create a tablespace, a directory is created in format PG_server_version_some_other_digit.
We check all tablespaces except pg_global for temp files.
For the error "ERROR: absolute path not allowed".
I cannot figure where the error seems to be coming from currently but it seems to be related to tablespace setup.
Are you using tablespaces? And if so, can you confirm the setup of the tablespaces?
Can you try break down the query? That way it would be easier to debug.
The first part
WITH tablespaces AS (
SELECT
spcname AS tbl_name,
coalesce(nullif(pg_tablespace_location(oid), ''), (current_setting('data_directory') || '/base')) AS tbl_location
FROM pg_tablespace
),
tablespace_suffix AS (
SELECT
tbl_name,
tbl_location || '/pgsql_tmp' AS path
FROM tablespaces
WHERE tbl_name = 'pg_default'
UNION ALL
SELECT
tbl_name,
tbl_location || '/' || path || '/pgsql_tmp'
FROM tablespaces, LATERAL pg_ls_dir(tbl_location) AS path
WHERE path ~ ('PG_' || substring(current_setting('server_version') FROM '^(?:\d\.\d\d?|\d+)'))
)
SELECT * FROM tablespace_suffix;
You mentioned that you avoided using "pg_ls_tmpdir" in the query since it's new as of PG12, but the query is using it. Is there an earlier version of the query that does not use it?
I ask because I'm trying to wrap my head around which queries are eating up my temp space, and due to the fact that I'm running Aurora PostgreSQL in AWS RDS, I cannot use "pg_ls_tmpdir" (the "rds_superuser" permissions explicitly deny it).
I started working with RDS recently but I didn't check out this issue until now. So using pg_ls_tmpdir is indeed going to bypass the permission issue. I have now added a query which can be used on RDS, hopefully you find it useful. Cheers.
Hi, I believe you mean pg_ls_dir and pg_stat_file? Both functions are restricted to only superusers by default but execute can be granted to any user by a superuser.
I am not totally conversant with rds_superuser so you might not be able to call these functions.
Temporary files are cleaned up automatically once the queries using them are done processing or canceled. Deleting an in-use temporary files can lead to backend crashes or even server crashes.
Why do you want to delete the files? Are they stale/orphaned? You should only have orphaned/stale temporary files when there are crashes.
We're a place where coders share, stay up-to-date and grow their careers.
path ~ ('PG_' || substring(current_setting('server_version') FROM '^(?:\d.\d\d?|\d+)'))
what exactly is this part doing in the query especially FROM '^(?:\d.\d\d?|\d+)')??? query is failing with msg "ERROR: absolute path not allowed"
When you create a tablespace, a directory is created in format
PG_server_version_some_other_digit.We check all tablespaces except
pg_globalfor temp files.I cannot figure where the error seems to be coming from currently but it seems to be related to tablespace setup.
Are you using tablespaces? And if so, can you confirm the setup of the tablespaces?
Thank you.
Anything wrong with the tablespace setup
Can you try break down the query? That way it would be easier to debug.
The first part
Btw, which version of PostgreSQL is it and is it native PostgreSQL?
One simple solution if resource are available is to create a ram based file system and use that for your temp file destination.
You mentioned that you avoided using "pg_ls_tmpdir" in the query since it's new as of PG12, but the query is using it. Is there an earlier version of the query that does not use it?
I ask because I'm trying to wrap my head around which queries are eating up my temp space, and due to the fact that I'm running Aurora PostgreSQL in AWS RDS, I cannot use "pg_ls_tmpdir" (the "rds_superuser" permissions explicitly deny it).
I started working with RDS recently but I didn't check out this issue until now. So using
pg_ls_tmpdiris indeed going to bypass the permission issue. I have now added a query which can be used on RDS, hopefully you find it useful. Cheers.Hi, I believe you mean
pg_ls_dirandpg_stat_file? Both functions are restricted to only superusers by default but execute can be granted to any user by a superuser.I am not totally conversant with
rds_superuserso you might not be able to call these functions.If the temporary file size is coming greater, please could you tell me how could I delete the temporary file in postgreSQL with the command?
Temporary files are cleaned up automatically once the queries using them are done processing or canceled. Deleting an in-use temporary files can lead to backend crashes or even server crashes.
Why do you want to delete the files? Are they stale/orphaned? You should only have orphaned/stale temporary files when there are crashes.