Re: Postgres 9.2.8 crash sporadically on Windows

From: "Sofer, Yuval" <Yuval_Sofer(at)bmc(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Postgres 9.2.8 crash sporadically on Windows
Date: 2014-04-08 11:44:23
Message-ID: 2C0926ABD16BB641A8E2F11A549200425564A05B29@PHXCCRPRD01.adprod.bmc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

code is attached below - c and h file , as well as the sql to create the function in postgres repository.

by the way, no one touched this code for several years (we first used it in PG 8.2.4)

dbutils.h:

/*

* dbutils.h

*

*/

#ifndef DBUTILS_H

#define DBUTILS_H

#include "fmgr.h"

/*

* External declarations

*/

extern Datum dbutils_get_diskinfo(PG_FUNCTION_ARGS);

#endif /* DBUTILS_H */

dbutils.c:

/*

* dbutils.c

*

*/

#include "postgres.h"

#include "fmgr.h"

#include "utils/builtins.h"

#include "dbutils.h"

#ifndef WIN32

#include <sys/types.h>

#include <sys/statvfs.h>

#endif

PG_MODULE_MAGIC;

/* general utility */

#define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp)))

#define GET_STR(textp) DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp)))

#define DBUTILS_DISK_INFO_TOTAL 1

#define DBUTILS_DISK_INFO_FREE 2

/*

* Getting disk information from a drive/directory

*/

PG_FUNCTION_INFO_V1(dbutils_get_diskinfo);

Datum

dbutils_get_diskinfo(PG_FUNCTION_ARGS)

{

char *pPathName = NULL;

int property;

char msg[1024];

#ifdef WIN32

BOOL fResult = FALSE;

__int64 i64FreeBytesToCaller;

__int64 i64TotalBytes;

__int64 i64FreeBytes;

__int64 i64Size = -1;

#else

int fResult = -1;

long long llSize = -1;

u_long ulBlockSize = 0;

struct statvfs st;

#endif

if (PG_NARGS() == 2)

{

property = PG_GETARG_INT32(0);

pPathName = GET_STR(PG_GETARG_TEXT_P(1));

}

else

{

msg[0] = '\0';

ereport(ERROR,

(errcode(ERRCODE_RAISE_EXCEPTION),

errmsg("Missing function arguments"),

errdetail("%s", msg)));

PG_RETURN_INT64(-1);

}

#ifdef WIN32

fResult = GetDiskFreeSpaceEx(pPathName,

(PULARGE_INTEGER)&i64FreeBytesToCaller,

(PULARGE_INTEGER)&i64TotalBytes,

(PULARGE_INTEGER)&i64FreeBytes);

if (fResult)

{

switch (property)

{

case DBUTILS_DISK_INFO_TOTAL:

i64Size = i64TotalBytes;

break;

case DBUTILS_DISK_INFO_FREE:

i64Size = i64FreeBytesToCaller;

break;

default:

msg[0] = '\0';

ereport(ERROR,

(errcode(ERRCODE_RAISE_EXCEPTION),

errmsg("Unknown disk info property"),

errdetail("%s", msg)));

}

PG_RETURN_INT64(i64Size);

}

else

{

sprintf(msg, "GetDiskFreeSpaceEx failed with error code: %ld", GetLastError());

ereport(ERROR,

(errcode(ERRCODE_RAISE_EXCEPTION),

errmsg("Unable to get disk info"),

errdetail("%s", msg)));

PG_RETURN_INT64(-1);

}

#else

fResult = statvfs(pPathName, &st);

if(fResult == 0)

{

/* f_frsize is sometimes empty so use f_bsize instead */

ulBlockSize = st.f_frsize ? st.f_frsize : st.f_bsize;

/* Note: in Linux st.f_frsize is larger than the file system block size and */

/* therefore the calculated free space is lower than the actual free space. */

switch (property)

{

case DBUTILS_DISK_INFO_TOTAL:

llSize = (long long)ulBlockSize * (long long)st.f_blocks;

break;

case DBUTILS_DISK_INFO_FREE:

llSize = (long long)ulBlockSize * (long long)st.f_bavail;

break;

default:

msg[0] = '\0';

ereport(ERROR,

(errcode(ERRCODE_RAISE_EXCEPTION),

errmsg("Unknown disk info property"),

errdetail("%s", msg)));

}

PG_RETURN_INT64(llSize);

}

else

{

sprintf(msg, "statvfs failed with error code: %d, message: %s ", errno, strerror(errno));

ereport(ERROR,

(errcode(ERRCODE_RAISE_EXCEPTION),

errmsg("Unable to get disk info"),

errdetail("%s", msg)));

PG_RETURN_INT64(-1);

}

#endif

PG_RETURN_INT64(-1);

}

dbutils.sql:

CREATE OR REPLACE FUNCTION dbutils_get_diskinfo (int, text)

RETURNS int8

AS 'MODULE_PATHNAME','dbutils_get_diskinfo'

LANGUAGE C STRICT;

[cid:image001(dot)png(at)01CF5339(dot)089C0E40]

Thanks,

Yuval

-----Original Message-----
From: Andres Freund [mailto:andres(at)2ndquadrant(dot)com]
Sent: Tuesday, April 08, 2014 1:15 PM
To: Sofer, Yuval
Cc: Tom Lane; pgsql-bugs(at)postgresql(dot)org
Subject: Re: [BUGS] Postgres 9.2.8 crash sporadically on Windows

On 2014-04-08 05:12:16 -0500, Sofer, Yuval wrote:

> Also, we use one homemade function, which is being activated more often (to get disk usage information, using Windows API).

> Anyway, I don't think it is the problem - whenever I activate it, I get the expected results.

> I activated it for several times - Postgres didn't reports anything unusual.

I still would bet it's related to that.

> >>Is there another exit report for the same PID just above the quoted log extract?

> No error reported above this message

It's not really the error, but the statements I am interested in.

> Let me know if you need more info. I can send you any c code or the PL functions which using these contributions.

That would be useful.

Greetings,

Andres Freund

--

Andres Freund http://www.2ndQuadrant.com/

PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeff 2014-04-08 13:18:22 Re: BUG #9898: WindowAgg's causing horrific plans
Previous Message Heikki Linnakangas 2014-04-08 10:16:37 Re: Configuring Standby Server in PostgreSQL 9.3.3