diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2013-04-17 15:58:04 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2013-04-17 15:58:04 +0200 |
commit | 36b1a442815ebe821aaaf6388fbd0d75b853a44a (patch) | |
tree | af19769c360c12fbbc17380adb68e68077de39ff /pgsql.c | |
parent | b431181bd1830beed98aed6569fe399a3636c88b (diff) | |
download | pgfuse-36b1a442815ebe821aaaf6388fbd0d75b853a44a.tar.gz pgfuse-36b1a442815ebe821aaaf6388fbd0d75b853a44a.tar.bz2 |
improved statfs (symlink handling, handling of default PGDATA)
Diffstat (limited to 'pgsql.c')
-rw-r--r-- | pgsql.c | 55 |
1 files changed, 48 insertions, 7 deletions
@@ -984,6 +984,48 @@ static int get_default_tablespace( PGconn *conn, int verbose ) return oid; } +static char *get_data_directory( PGconn *conn ) +{ + PGresult *res; + char *data; + + /* in the questionable case we have super user rights we + * can ask the server for the default path */ + res = PQexec( conn, "select setting from pg_settings where name = 'data_directory'" ); + + if( PQresultStatus( res ) != PGRES_TUPLES_OK ) { + syslog( LOG_ERR, "Error getting data_directory: %s", PQerrorMessage( conn ) ); + PQclear( res ); + return NULL; + } + + /* No permissions results in an empty result set */ + if( PQntuples( res ) == 0 ) { + PQclear( res ); + + /* No location, tablespace resides in PGDATA, + * usually it lies in /var/lib/postgres, + * /var/lib/postgresql, + * /var/lib/pgsql or /var/lib/postgresql/9.1/main + */ +#ifdef __linux__ + data = strdup( "/var/lib/postgres" ); +#else + /* TODO, but usually BSD stores it on /usr/local, MacOs + * would be different, but there a lot else is also different.. + */ + data = strdup( "/usr/local" ); +#endif + return data; + } + + data = strdup( PQgetvalue( res, 0, 0 ) ); + + PQclear( res ); + + return data; +} + static char *get_tablespace_location( PGconn *conn, const int oid, int verbose ) { PGresult *res; @@ -1012,6 +1054,12 @@ static char *get_tablespace_location( PGconn *conn, const int oid, int verbose ) data = strdup( PQgetvalue( res, 0, 0 ) ); PQclear( res ); + + /* no direct information in the catalog about the table space location, try + * other means */ + if( strcmp( data, "" ) == 0 ) { + data = get_data_directory( conn ); + } return data; } @@ -1078,13 +1126,6 @@ int psql_get_tablespace_locations( PGconn *conn, char **location, size_t *nof_oi location[i] = get_tablespace_location( conn, oid[i], verbose ); } - /* TODO: */ - for( i = 0; i < *nof_oids; i++ ) { - if( !location[i] ) { - /* No location, tablespace resides in PGDATA */ - } - } - for( i = 0; i < *nof_oids; i++ ) { if( verbose ) { syslog( LOG_DEBUG, "Free blocks calculation, seen tablespace OID %d, %s", |