3 * $Header: /cvsroot/pgpool/pgpool-II/sql/pgpool-recovery/pgpool-recovery.c,v 1.6.2.2 2009/07/14 08:42:24 t-ishii Exp $
5 * pgpool-recovery: exec online recovery script from SELECT statement.
7 * Copyright (c) 2003-2009 PgPool Global Development Group
9 * Permission to use, copy, modify, and distribute this software and
10 * its documentation for any purpose and without fee is hereby
11 * granted, provided that the above copyright notice appear in all
12 * copies and that both that copyright notice and this permission
13 * notice appear in supporting documentation, and that the name of the
14 * author not be used in advertising or publicity pertaining to
15 * distribution of the software without specific, written prior
16 * permission. The author makes no representations about the
17 * suitability of this software for any purpose. It is provided "as
18 * is" without express or implied warranty.
23 #include "miscadmin.h"
24 #include "executor/spi.h"
26 #include "utils/builtins.h" /* PostgreSQL 8.4 needs this for textout */
28 #define REMOTE_START_FILE "pgpool_remote_start"
32 #ifdef PG_MODULE_MAGIC
36 PG_FUNCTION_INFO_V1(pgpool_recovery);
37 PG_FUNCTION_INFO_V1(pgpool_remote_start);
39 extern Datum pgpool_recovery(PG_FUNCTION_ARGS);
40 extern Datum pgpool_remote_start(PG_FUNCTION_ARGS);
42 static char recovery_script[1024];
45 pgpool_recovery(PG_FUNCTION_ARGS)
48 char *script = DatumGetCString(DirectFunctionCall1(textout,
49 PointerGetDatum(PG_GETARG_TEXT_P(0))));
51 char *remote_host = DatumGetCString(DirectFunctionCall1(textout,
52 PointerGetDatum(PG_GETARG_TEXT_P(1))));
53 char *remote_data_directory = DatumGetCString(DirectFunctionCall1(textout,
54 PointerGetDatum(PG_GETARG_TEXT_P(2))));
58 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
59 (errmsg("must be superuser to use pgpool_recovery function"))));
61 snprintf(recovery_script, sizeof(recovery_script), "%s/%s %s %s %s",
62 DataDir, script, DataDir, remote_host,
63 remote_data_directory);
64 elog(DEBUG1, "recovery_script: %s", recovery_script);
65 r = system(recovery_script);
69 elog(ERROR, "pgpool_recovery failed");
77 pgpool_remote_start(PG_FUNCTION_ARGS)
80 char *remote_host = DatumGetCString(DirectFunctionCall1(textout,
81 PointerGetDatum(PG_GETARG_TEXT_P(0))));
82 char *remote_data_directory = DatumGetCString(DirectFunctionCall1(textout,
83 PointerGetDatum(PG_GETARG_TEXT_P(1))));
87 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
88 (errmsg("must be superuser to use pgpool_remote_start function"))));
90 snprintf(recovery_script, sizeof(recovery_script),
91 "%s/%s %s %s", DataDir, REMOTE_START_FILE,
92 remote_host, remote_data_directory);
93 elog(DEBUG1, "recovery_script: %s", recovery_script);
94 r = system(recovery_script);
98 elog(ERROR, "pgpool_remote_start failed");
101 PG_RETURN_BOOL(true);