@@ -527,3 +527,95 @@ ExecuteLetStmt(ParseState *pstate,
527
527
528
528
PopActiveSnapshot ();
529
529
}
530
+
531
+ /*
532
+ * pg_session_variables - designed for testing
533
+ *
534
+ * This is a function designed for testing and debugging. It returns the
535
+ * content of session variables as-is, and can therefore display data about
536
+ * session variables that were dropped, but for which this backend didn't
537
+ * process the shared invalidations yet.
538
+ */
539
+ Datum
540
+ pg_session_variables (PG_FUNCTION_ARGS )
541
+ {
542
+ #define NUM_PG_SESSION_VARIABLES_ATTS 8
543
+
544
+ InitMaterializedSRF (fcinfo , 0 );
545
+
546
+ if (sessionvars )
547
+ {
548
+ ReturnSetInfo * rsinfo = (ReturnSetInfo * ) fcinfo -> resultinfo ;
549
+ HASH_SEQ_STATUS status ;
550
+ SVariable svar ;
551
+
552
+ hash_seq_init (& status , sessionvars );
553
+
554
+ while ((svar = (SVariable ) hash_seq_search (& status )) != NULL )
555
+ {
556
+ Datum values [NUM_PG_SESSION_VARIABLES_ATTS ];
557
+ bool nulls [NUM_PG_SESSION_VARIABLES_ATTS ];
558
+ HeapTuple tp ;
559
+ bool var_is_valid = false;
560
+
561
+ memset (values , 0 , sizeof (values ));
562
+ memset (nulls , 0 , sizeof (nulls ));
563
+
564
+ values [0 ] = ObjectIdGetDatum (svar -> varid );
565
+ values [3 ] = ObjectIdGetDatum (svar -> typid );
566
+
567
+ /*
568
+ * It is possible that the variable has been dropped from the
569
+ * catalog, but not yet purged from the hash table.
570
+ */
571
+ tp = SearchSysCache1 (VARIABLEOID , ObjectIdGetDatum (svar -> varid ));
572
+
573
+ if (HeapTupleIsValid (tp ))
574
+ {
575
+ Form_pg_variable varform = (Form_pg_variable ) GETSTRUCT (tp );
576
+
577
+ /*
578
+ * It is also possible that a variable has been dropped and
579
+ * someone created a new variable with the same object ID. Use
580
+ * the catalog information only if that is not the case.
581
+ */
582
+ if (svar -> create_lsn == varform -> varcreate_lsn )
583
+ {
584
+ values [1 ] = CStringGetTextDatum (
585
+ get_namespace_name (varform -> varnamespace ));
586
+
587
+ values [2 ] = CStringGetTextDatum (NameStr (varform -> varname ));
588
+ values [4 ] = CStringGetTextDatum (format_type_be (svar -> typid ));
589
+ values [5 ] = BoolGetDatum (false);
590
+
591
+ values [6 ] = BoolGetDatum (
592
+ object_aclcheck (VariableRelationId , svar -> varid ,
593
+ GetUserId (), ACL_SELECT ) == ACLCHECK_OK );
594
+
595
+ values [7 ] = BoolGetDatum (
596
+ object_aclcheck (VariableRelationId , svar -> varid ,
597
+ GetUserId (), ACL_UPDATE ) == ACLCHECK_OK );
598
+
599
+ var_is_valid = true;
600
+ }
601
+
602
+ ReleaseSysCache (tp );
603
+ }
604
+
605
+ /* if there is no matching catalog entry, return null values */
606
+ if (!var_is_valid )
607
+ {
608
+ nulls [1 ] = true;
609
+ nulls [2 ] = true;
610
+ nulls [4 ] = true;
611
+ values [5 ] = BoolGetDatum (true);
612
+ nulls [6 ] = true;
613
+ nulls [7 ] = true;
614
+ }
615
+
616
+ tuplestore_putvalues (rsinfo -> setResult , rsinfo -> setDesc , values , nulls );
617
+ }
618
+ }
619
+
620
+ return (Datum ) 0 ;
621
+ }
0 commit comments