1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Add pg_file_sync() to adminpack extension.

This function allows us to fsync the specified file or directory.
It's useful, for example, when we want to sync the file that
pg_file_write() writes out or that COPY TO exports the data into,
for durability.

Author: Fujii Masao
Reviewed-By: Julien Rouhaud, Arthur Zakirov, Michael Paquier, Atsushi Torikoshi
Discussion: https://www.postgresql.org/message-id/CAHGQGwGY8uzZ_k8dHRoW1zDcy1Z7=5GQ+So4ZkVy2u=nLsk=hA@mail.gmail.com
This commit is contained in:
Fujii Masao
2020-01-24 20:42:52 +09:00
parent cc25464763
commit d694e0bb79
9 changed files with 89 additions and 4 deletions

View File

@ -43,6 +43,7 @@ PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(pg_file_write);
PG_FUNCTION_INFO_V1(pg_file_write_v1_1);
PG_FUNCTION_INFO_V1(pg_file_sync);
PG_FUNCTION_INFO_V1(pg_file_rename);
PG_FUNCTION_INFO_V1(pg_file_rename_v1_1);
PG_FUNCTION_INFO_V1(pg_file_unlink);
@ -215,6 +216,30 @@ pg_file_write_internal(text *file, text *data, bool replace)
return (count);
}
/* ------------------------------------
* pg_file_sync
*
* We REVOKE EXECUTE on the function from PUBLIC.
* Users can then grant access to it based on their policies.
*/
Datum
pg_file_sync(PG_FUNCTION_ARGS)
{
char *filename;
struct stat fst;
filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0), false);
if (stat(filename, &fst) < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not stat file \"%s\": %m", filename)));
fsync_fname_ext(filename, S_ISDIR(fst.st_mode), false, ERROR);
PG_RETURN_VOID();
}
/* ------------------------------------
* pg_file_rename - old version
*