mirror of https://github.com/citusdata/citus.git
Adds pg_dist_database_size
parent
24264f2e42
commit
62e1d37623
|
@ -4055,8 +4055,10 @@ citus_internal_database_command(PG_FUNCTION_ARGS)
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
citus_internal_pg_database_size_by_db_name(PG_FUNCTION_ARGS){
|
citus_internal_pg_database_size_by_db_name(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
CheckCitusVersion(ERROR);
|
CheckCitusVersion(ERROR);
|
||||||
|
|
||||||
PG_ENSURE_ARGNOTNULL(0, "dbName");
|
PG_ENSURE_ARGNOTNULL(0, "dbName");
|
||||||
|
@ -4065,20 +4067,20 @@ citus_internal_pg_database_size_by_db_name(PG_FUNCTION_ARGS){
|
||||||
Datum size = DirectFunctionCall1(pg_database_size_name, NameGetDatum(dbName));
|
Datum size = DirectFunctionCall1(pg_database_size_name, NameGetDatum(dbName));
|
||||||
|
|
||||||
PG_RETURN_DATUM(size);
|
PG_RETURN_DATUM(size);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
citus_internal_pg_database_size_by_db_oid(PG_FUNCTION_ARGS){
|
citus_internal_pg_database_size_by_db_oid(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
CheckCitusVersion(ERROR);
|
CheckCitusVersion(ERROR);
|
||||||
|
|
||||||
PG_ENSURE_ARGNOTNULL(0, "dbOid");
|
PG_ENSURE_ARGNOTNULL(0, "dbOid");
|
||||||
|
|
||||||
Oid dbOid = PG_GETARG_OID(0);
|
Oid dbOid = PG_GETARG_OID(0);
|
||||||
Datum size = DirectFunctionCall1(pg_database_size_oid, ObjectIdGetDatum(dbOid));
|
Datum size = DirectFunctionCall1(pg_database_size_oid, ObjectIdGetDatum(dbOid));
|
||||||
|
|
||||||
PG_RETURN_DATUM(size);
|
PG_RETURN_DATUM(size);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4121,8 +4123,10 @@ GroupLookupFromDatabase(int64 databaseOid, bool missingOk)
|
||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum citus_internal_database_size(PG_FUNCTION_ARGS){
|
|
||||||
|
|
||||||
|
Datum
|
||||||
|
citus_internal_database_size(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
uint32 connectionFlag = 0;
|
uint32 connectionFlag = 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -4141,18 +4145,20 @@ Datum citus_internal_database_size(PG_FUNCTION_ARGS){
|
||||||
"SELECT citus_internal.pg_database_size_local('%s')",
|
"SELECT citus_internal.pg_database_size_local('%s')",
|
||||||
dbName->data);
|
dbName->data);
|
||||||
|
|
||||||
//get database oid
|
/*get database oid */
|
||||||
bool missingOk = true;
|
bool missingOk = true;
|
||||||
Oid databaseOid = get_database_oid(dbName->data, missingOk);
|
Oid databaseOid = get_database_oid(dbName->data, missingOk);
|
||||||
elog(INFO, "citus_internal_database_oid: %d", databaseOid);
|
elog(INFO, "citus_internal_database_oid: %d", databaseOid);
|
||||||
|
|
||||||
//get group id
|
/*get group id */
|
||||||
int groupId = GroupLookupFromDatabase(databaseOid, missingOk);
|
int groupId = GroupLookupFromDatabase(databaseOid, missingOk);
|
||||||
if (groupId < 0){
|
if (groupId < 0)
|
||||||
ereport(ERROR, (errmsg("could not find valid entry for database %d ", databaseOid)));
|
{
|
||||||
|
ereport(ERROR, (errmsg("could not find valid entry for database %d ",
|
||||||
|
databaseOid)));
|
||||||
PG_RETURN_INT64(-1);
|
PG_RETURN_INT64(-1);
|
||||||
}
|
}
|
||||||
elog(INFO, "group id: %d",groupId);
|
elog(INFO, "group id: %d", groupId);
|
||||||
|
|
||||||
WorkerNode *workerNode = LookupNodeForGroup(groupId);
|
WorkerNode *workerNode = LookupNodeForGroup(groupId);
|
||||||
|
|
||||||
|
@ -4162,39 +4168,40 @@ Datum citus_internal_database_size(PG_FUNCTION_ARGS){
|
||||||
elog(INFO, "workerNodeName: %s", workerNodeName);
|
elog(INFO, "workerNodeName: %s", workerNodeName);
|
||||||
elog(INFO, "workerNodePort: %d", workerNodePort);
|
elog(INFO, "workerNodePort: %d", workerNodePort);
|
||||||
|
|
||||||
if (groupId == GetLocalGroupId()){
|
if (groupId == GetLocalGroupId())
|
||||||
//local database
|
{
|
||||||
|
/*local database */
|
||||||
elog(INFO, "local database");
|
elog(INFO, "local database");
|
||||||
PG_RETURN_INT64(DirectFunctionCall1(citus_internal_pg_database_size_by_db_name, NameGetDatum(dbName)));
|
PG_RETURN_INT64(DirectFunctionCall1(citus_internal_pg_database_size_by_db_name,
|
||||||
|
NameGetDatum(dbName)));
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
elog(INFO, "remote database");
|
elog(INFO, "remote database");
|
||||||
//remote database
|
/*remote database */
|
||||||
MultiConnection *connection = GetNodeConnection(connectionFlag, workerNodeName,
|
MultiConnection *connection = GetNodeConnection(connectionFlag, workerNodeName,
|
||||||
workerNodePort);
|
workerNodePort);
|
||||||
int queryResult = ExecuteOptionalRemoteCommand(connection, databaseSizeQuery->data,
|
int queryResult = ExecuteOptionalRemoteCommand(connection,
|
||||||
&result);
|
databaseSizeQuery->data,
|
||||||
|
&result);
|
||||||
int64 size = 0;
|
int64 size = 0;
|
||||||
|
|
||||||
if (queryResult != 0)
|
if (queryResult != 0)
|
||||||
{
|
{
|
||||||
ereport(WARNING, (errcode(ERRCODE_CONNECTION_FAILURE),
|
ereport(WARNING, (errcode(ERRCODE_CONNECTION_FAILURE),
|
||||||
errmsg("could not connect to %s:%d to get size of "
|
errmsg("could not connect to %s:%d to get size of "
|
||||||
"database \"%s\"",
|
"database \"%s\"",
|
||||||
workerNodeName, workerNodePort,
|
workerNodeName, workerNodePort,
|
||||||
dbName->data)));
|
dbName->data)));
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
size = ParseIntField(result, 0, 0);
|
size = ParseIntField(result, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
ClearResults(connection, failOnError);
|
ClearResults(connection, failOnError);
|
||||||
PG_RETURN_INT64(size);
|
PG_RETURN_INT64(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,4 @@ ALTER TABLE citus.pg_dist_database SET SCHEMA pg_catalog;
|
||||||
GRANT SELECT ON pg_catalog.pg_dist_database TO public;
|
GRANT SELECT ON pg_catalog.pg_dist_database TO public;
|
||||||
|
|
||||||
#include "udfs/citus_internal_pg_database_size_local/12.2-1.sql"
|
#include "udfs/citus_internal_pg_database_size_local/12.2-1.sql"
|
||||||
-- #include "udfs/citus_pg_dist_database/12.2-1.sql"
|
#include "udfs/citus_pg_dist_database/12.2-1.sql"
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
LANGUAGE C
|
LANGUAGE C
|
||||||
VOLATILE
|
VOLATILE
|
||||||
AS 'MODULE_PATHNAME', $$citus_internal_database_size$$;
|
AS 'MODULE_PATHNAME', $$citus_internal_database_size$$;
|
||||||
COMMENT ON FUNCTION pg_catalog.pg_dist_database_size(oid) IS
|
COMMENT ON FUNCTION pg_catalog.pg_dist_database_size(name) IS
|
||||||
'calculates the size of a database in bytes by its name in a multi-node cluster';
|
'calculates the size of a database in bytes by its name in a multi-node cluster';
|
||||||
|
|
|
@ -12,11 +12,10 @@
|
||||||
#define CITUS_PG_DIST_DATABASE_H
|
#define CITUS_PG_DIST_DATABASE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct FormData_pg_dist_database
|
typedef struct FormData_pg_dist_database
|
||||||
{
|
{
|
||||||
Oid databaseid;
|
Oid databaseid;
|
||||||
int groupid;
|
int groupid;
|
||||||
} FormData_pg_dist_database;
|
} FormData_pg_dist_database;
|
||||||
|
|
||||||
#define Anum_pg_dist_database_databaseid 1
|
#define Anum_pg_dist_database_databaseid 1
|
||||||
|
@ -30,4 +29,5 @@ typedef struct FormData_pg_dist_database
|
||||||
typedef FormData_pg_dist_database *Form_pg_dist_database;
|
typedef FormData_pg_dist_database *Form_pg_dist_database;
|
||||||
#endif /* CITUS_PG_DIST_DATABASE_H */
|
#endif /* CITUS_PG_DIST_DATABASE_H */
|
||||||
|
|
||||||
#define PgDistDatabaseRelationId() (get_relname_relid("pg_dist_database", PG_CATALOG_NAMESPACE))
|
#define PgDistDatabaseRelationId() (get_relname_relid("pg_dist_database", \
|
||||||
|
PG_CATALOG_NAMESPACE))
|
||||||
|
|
Loading…
Reference in New Issue