postgresqlerror-handlingsasproc-sqlsas-studio

Unkown Error & Session Problem Detected when loading large Postgres Tables into SAS Studio


What I encountered

I'm programming with Flows in SAS Studio in the ViyaCloud. While trying to load large Tables from a PostgreSQL Database I encountered the following error combination:

Two Error Pop-Ups. One stating that a problem with the SAS Session is detected. One "Run Flow" is blank.

I narrowed it down to too large Postgres tables conflicting with SAS Work library, as the problem also appears within 'normal' SAS programms and mindless mundane queries.

Basic example - Try it yourself

I tried different things but it narrows down to this simple list:

/* 1x ID, 10 Observations - Successfull */
PROC SQL OUTOBS=10;
    CREATE TABLE WORK.Test_Select_All AS SELECT t1.* FROM POSTGRES.RAND_DUMMY_DATA t1
    WHERE t1.id <= 1
    ;
QUIT;
RUN;
/* All, 10 Observations - Fails */
PROC SQL OUTOBS=10;
    CREATE TABLE WORK.Test_Select_All AS SELECT t1.* FROM POSTGRES.RAND_DUMMY_DATA t1
    ;
QUIT;
RUN;

Regarding the connection:

PROC CONTENTS of DB Table

INFO1 VAL1 INFO2 VAL2
Data Set Name POSTGRES.RAND_DUMMY_DATA Observations .
Member Type DATA Variables 20
Engine POSTGRES Indexes 0
Created . Observation Length 0
Last Modified . Deleted Observations 0
Protection Compressed NO
Data Set Type Sorted NO
Label
Data Representation Default
Encoding Default
# Variable Type Len Format Informat Label
2 char_1 Char 4 $4. $4. char_1
3 char_2 Char 4 $4. $4. char_2
4 char_3 Char 12 $12. $12. char_3
1 date Num 8 DATETIME 25.6 DATETIME 25.6 date
20 id Num 8 id
5 val_1 Num 8 val_1
6 val_2 Num 8 val_2
7 val_3 Num 8 val_3
8 val_4 Num 8 val_4
9 val_5 Num 8 val_5
10 val_6 Num 8 val_6
11 val_7 Num 8 val_7
12 val_8 Num 8 val_8
13 val_9 Num 8 val_9
14 val_10 Num 8 val_10
15 val_11 Num 8 val_11
16 val_12 Num 8 val_12
17 val_13 Num 8 val_13
18 val_14 Num 8 val_14
19 val_15 Num 8 val_15

What I expected

That the DB table would be loaded into the Work Library without any errors, as runs with less data worked fine.

Update - Connection Issue?

After I added CONOPTS="UseDeclarefetch=1;FetchSize=250000" to my libname statement, my minimal example I posted works. But for other reasons I currently can't try more complex / the original ones.

I suspect that it's a RAM issue o.eq. of the Workspace and I need to adjust the connection to the DB further to not kill the process. Or request more RAM I guess. Keeping you updated.


Solution

  • I found a fix for this, even if I quite not understand the details.

    It seems to be a memory/caching problem, because our default was so that everything was loaded at once. The following helped us to prevent this from happening:

    1. Connection Options

    Add the specific connection option to fetch the data 'batchwise' to the library definition like:

    libname YOURNAME libdef='defSource' CONOPTS="UseDeclareFetch=1;FetchSize=500000";

    2. Environment Variables

    Let your Admin declare the fetch size in the environmentvariables that are called SAS_PG_USEDECLAREFETCH and SAS_PG_FETCHSIZE like above...