1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-06 09:50:20 +00:00

Postgresql port setting

This commit is contained in:
cuihaikuo
2017-01-16 15:56:51 +08:00
parent 5f831a8579
commit bcd7ad8f0b
7 changed files with 23 additions and 4 deletions

View File

@@ -95,6 +95,7 @@ db_conn_pool_new_mysql (const char *host,
DBConnPool *
db_conn_pool_new_pgsql (const char *host,
unsigned int port,
const char *user,
const char *password,
const char *db_name,
@@ -124,7 +125,7 @@ db_conn_pool_new_pgsql (const char *host,
DBConnPool *pool;
pool = pgsql_db_conn_pool_new (host, user, password, db_name, unix_socket);
pool = pgsql_db_conn_pool_new (host, port, user, password, db_name, unix_socket);
init_conn_pool_common (pool, max_connections);
return pool;

View File

@@ -29,6 +29,7 @@ db_conn_pool_new_mysql (const char *host,
DBConnPool *
db_conn_pool_new_pgsql (const char *host,
unsigned int port,
const char *user,
const char *password,
const char *db_name,

View File

@@ -8,6 +8,7 @@
typedef struct PGDBConnPool {
DBConnPool parent;
char *host;
unsigned int port;
char *user;
char *password;
char *db_name;
@@ -16,6 +17,7 @@ typedef struct PGDBConnPool {
DBConnPool *
pgsql_db_conn_pool_new (const char *host,
unsigned int port,
const char *user,
const char *password,
const char *db_name,
@@ -24,6 +26,7 @@ pgsql_db_conn_pool_new (const char *host,
PGDBConnPool *pool = g_new0 (PGDBConnPool, 1);
pool->host = g_strdup (host);
pool->port = port;
pool->user = g_strdup (user);
pool->password = g_strdup (password);
pool->db_name = g_strdup(db_name);
@@ -88,6 +91,10 @@ connect_pgsql (PGDBConnPool *pool, GError **error)
g_string_append_printf (buf, "host='%s' ", pool->host);
}
if (pool->port > 0) {
g_string_append_printf (buf, "port=%u ", pool->port);
}
g_string_append_printf (buf, "dbname='%s' ", pool->db_name);
db = PQconnectdb (buf->str);

View File

@@ -3,6 +3,7 @@
DBConnPool *
pgsql_db_conn_pool_new (const char *host,
unsigned int port,
const char *user,
const char *password,
const char *db_name,

View File

@@ -56,6 +56,7 @@ seaf_db_new_mysql (const char *host,
SeafDB *
seaf_db_new_pgsql (const char *host,
unsigned int port,
const char *user,
const char *passwd,
const char *db_name,
@@ -72,7 +73,7 @@ seaf_db_new_pgsql (const char *host,
db->type = SEAF_DB_TYPE_PGSQL;
db->pool = db_conn_pool_new_pgsql (host, user, passwd, db_name, unix_socket,
db->pool = db_conn_pool_new_pgsql (host, port, user, passwd, db_name, unix_socket,
max_connections);
return db;

View File

@@ -26,6 +26,7 @@ seaf_db_new_mysql (const char *host,
SeafDB *
seaf_db_new_pgsql (const char *host,
unsigned int port,
const char *user,
const char *passwd,
const char *db_name,

View File

@@ -134,6 +134,7 @@ static int
pgsql_db_start (SeafileSession *session)
{
char *host, *user, *passwd, *db, *unix_socket;
unsigned int port;
GError *error = NULL;
host = seaf_key_file_get_string (session->config, "database", "host", &error);
@@ -159,11 +160,17 @@ pgsql_db_start (SeafileSession *session)
seaf_warning ("DB name not set in config.\n");
return -1;
}
port = g_key_file_get_integer (session->config,
"database", "port", &error);
if (error) {
port = 0;
g_clear_error (&error);
}
unix_socket = seaf_key_file_get_string (session->config,
"database", "unix_socket", &error);
session->db = seaf_db_new_pgsql (host, user, passwd, db, unix_socket,
session->db = seaf_db_new_pgsql (host, port, user, passwd, db, unix_socket,
DEFAULT_MAX_CONNECTIONS);
if (!session->db) {
seaf_warning ("Failed to start pgsql db.\n");