Re: [HACKERS] Archive recovery won't be completed on some situation.

2014-03-20 Thread Kyotaro HORIGUCHI
Hi, I confirmed that 82233ce7ea4 surely did it.

At Wed, 19 Mar 2014 09:35:16 -0300, Alvaro Herrera wrote
 Fujii Masao escribió:
  On Wed, Mar 19, 2014 at 7:57 PM, Heikki Linnakangas
  hlinnakan...@vmware.com wrote:
 
   9.4 canceles backup mode even on immediate shutdown so the
   operation causes no problem, but 9.3 and before are doesn't.
  
   Hmm, I don't think we've changed that behavior in 9.4.
  
  ISTM 82233ce7ea42d6ba519aaec63008aff49da6c7af changed immdiate
  shutdown that way.
 
 Uh, interesting.  I didn't see that secondary effect.  I hope it's not
 for ill?

The crucial factor for the behavior change is that pmdie has
become not to exit immediately for SIGQUIT. 'case SIGQUIT:' in
pmdie() ended with ExitPostmaster(0) before the patch but now
it ends with 'PostmasterStateMachine(); break;' so continues to
run with pmState = PM_WAIT_BACKENDS, similar to SIGINT (fast
shutdown).

After all, pmState changes to PM_NO_CHILDREN via PM_WAIT_DEAD_END
by SIGCHLDs from non-significant processes, then CancelBackup().

Focusing on the point described above, the small patch below
rewinds the behavior back to 9.3 and before but I don't know the
appropriateness in regard to the intention of the patch.

diff --git a/src/backend/postmaster/postmaster.c 
b/src/backend/postmaster/postmaster.c
index e9072b7..f87c25c 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -2498,16 +2498,7 @@ pmdie(SIGNAL_ARGS)
(errmsg(received immediate shutdown 
request)));
 
TerminateChildren(SIGQUIT);
-   pmState = PM_WAIT_BACKENDS;
-
-   /* set stopwatch for them to die */
-   AbortStartTime = time(NULL);
-
-   /*
-* Now wait for backends to exit.  If there are none,
-* PostmasterStateMachine will take the next step.
-*/
-   PostmasterStateMachine();
+   ExitPostmaster(0);
break;
}

regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] four minor proposals for 9.5

2014-03-20 Thread Mark Kirkwood

On 20/03/14 13:28, Josh Berkus wrote:


3. relation limit - possibility to set session limit for maximum size of
relations. Any relation cannot be extended over this limit in session, when
this value is higher than zero. Motivation - we use lot of queries like
CREATE TABLE AS SELECT .. , and some very big results decreased a disk free
space too much. It was high risk in our multi user environment. Motivation
is similar like temp_files_limit.


I'd think the size of the relation you were creating would be difficult
to measure.  Also, would this apply to REINDEX/VACUUM FULL/ALTER?  Or
just CREATE TABLE AS/SELECT INTO?



Also I think this would probably only make sense for TEMPORARY tables - 
otherwise you can get this sort of thing going on:


- you create a table and you have set a relation size limit
- you commit and keep working
- I add a whole lot of rows to your new table (taking it over the limit)
- you go to add some more rows to this table...

Should you now be stopped working? Does this feature need to track *who* 
added which chunks of a table (suspect very difficult to do sensibly)?


Regards

Mark


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Archive recovery won't be completed on some situation.

2014-03-20 Thread Kyotaro HORIGUCHI
Hello,

At Wed, 19 Mar 2014 19:34:10 +0900, Fujii Masao wrote
  Agreed. Attached patches do that and I could recover the
  database state with following steps,
 
 Adding new option looks like new feature rather than bug fix.
 I'm afraid that the backpatch of such a change to 9.3 or before
 is not acceptable.

Me too. But on the other hand it simplly is a relief for the
consequence of the behavior of server (altough it was ill
operation:), and especially it is needed for at least 9.1 which
seems cannot be saved without it. Plus it has utterly no impact
on servers' behavior of any corresponding versions. So I hope it
is accepted.

regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Archive recovery won't be completed on some situation.

2014-03-20 Thread Kyotaro HORIGUCHI
Hello,

 On 03/19/2014 10:28 AM, Kyotaro HORIGUCHI wrote:
  The*problematic*  operation sequence I saw was performed by
  pgsql-RA/Pacemaker. It stops a server already with immediate mode
  and starts the Master as a Standby at first, then
  promote. Focusing on this situation, there would be reasonable to
  reset backup positions.
 
 Well, that's scary. I would suggest doing a fast shutdown instead. But
 if you really want to do an immediate shutdown, you should delete the
 backup_label file after the shutdown

We'd also said them the former thing on several occations. They
answered that they hate shutdown checkpoint to take long time
before shutdown is completed. The latter one has not come on my
mind and seems promising. Thank you for the suggestion.

 When restarting after immediate shutdown and a backup_label file is
 present, the system doesn't know if the system crashed during a
 backup, and it needs to perform crash recovery, or if you're trying
 restore from a backup. It makes a compromise, and starts recovery from
 the checkpoint given in the backup_label, as if it was restoring from
 a backup, but if it doesn't see a backup-end WAL record, it just
 starts up anyway (which would be wrong if you are indeed restoring
 from a backup). But if you create a recovery.conf file, that indicates
 that you are definitely restoring from a backup, so it's more strict
 and insists that the backup-end record must be replayed.
 
  9.4 canceles backup mode even on
  immediate shutdown so the operation causes no problem, but 9.3
  and before are doesn't.
 
 Hmm, I don't think we've changed that behavior in 9.4.

Now pmdie behaves in the similar manner between fast and
immediate shutdown after 82233ce7ea42d6ba519. It is an side
effect of a change on immediate shutdown which make it to wait
the children to die by SIGQUIT.

regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] four minor proposals for 9.5

2014-03-20 Thread Pavel Stehule
2014-03-20 5:36 GMT+01:00 Amit Kapila amit.kapil...@gmail.com:

 On Wed, Mar 19, 2014 at 9:04 PM, Pavel Stehule pavel.steh...@gmail.com
 wrote:
  Hello
 
  I wrote a few patches, that we use in our production. These patches are
  small, but I hope, so its can be interesting for upstream:
 
  1. cancel time - we log a execution time cancelled statements
 
  2. fatal verbose - this patch ensure a verbose log for fatal errors. It
  simplify a investigation about reasons of error.
 
  3. relation limit - possibility to set session limit for maximum size of
  relations. Any relation cannot be extended over this limit in session,
 when
  this value is higher than zero. Motivation - we use lot of queries like
  CREATE TABLE AS SELECT .. , and some very big results decreased a disk
 free
  space too much. It was high risk in our multi user environment.
 Motivation
  is similar like temp_files_limit.

 So if there is error on reaching max threshold size, won't it loose all
 data or
 is that expected?


Exception is expected



 Also I think it might not be applicable for all table inserts, as normally
 checkpointer/bgrwriter flushes data, so you might not be able to estimate
 size immediately when your SQL statement is executing.

 Won't it better to have LIMIT Rows in Select statement or generically
 have table level option for Max Rows?


It significantly harder to expect N for LIMIT - there are lot of varlena
types, so sometimes you can be too strict, sometimes you can be too tolerant




 With Regards,
 Amit Kapila.
 EnterpriseDB: http://www.enterprisedb.com



Re: [HACKERS] four minor proposals for 9.5

2014-03-20 Thread Pavel Stehule
2014-03-20 7:25 GMT+01:00 Mark Kirkwood mark.kirkw...@catalyst.net.nz:

 On 20/03/14 13:28, Josh Berkus wrote:

  3. relation limit - possibility to set session limit for maximum size of
 relations. Any relation cannot be extended over this limit in session,
 when
 this value is higher than zero. Motivation - we use lot of queries like
 CREATE TABLE AS SELECT .. , and some very big results decreased a disk
 free
 space too much. It was high risk in our multi user environment.
 Motivation
 is similar like temp_files_limit.


 I'd think the size of the relation you were creating would be difficult
 to measure.  Also, would this apply to REINDEX/VACUUM FULL/ALTER?  Or
 just CREATE TABLE AS/SELECT INTO?


 Also I think this would probably only make sense for TEMPORARY tables -
 otherwise you can get this sort of thing going on:

 - you create a table and you have set a relation size limit
 - you commit and keep working
 - I add a whole lot of rows to your new table (taking it over the limit)
 - you go to add some more rows to this table...


you cannot to across session limit and is not important if you do inserts
more times or once.

This patch is very simple - it is only one safeguard against too low space
on disc in very dynamic multi user enironment

--- ./src/backend/storage/smgr/md.c 2014-02-26 17:29:36.864189192 +0100
***
*** 27,32 
--- 27,33 
  #include storage/bufmgr.h
  #include storage/relfilenode.h
  #include storage/smgr.h
+ #include utils/guc.h
  #include utils/hsearch.h
  #include utils/memutils.h
  #include pg_trace.h
***
*** 180,185 
--- 181,191 
  static BlockNumber _mdnblocks(SMgrRelation reln, ForkNumber forknum,
   MdfdVec *seg);

+ /*
+  *  limits for relations size
+  */
+ int max_blocks;

  /*
   *mdinit() -- Initialize private state for magnetic disk storage
manager.
***
*** 475,480 
--- 481,494 
Assert(blocknum = mdnblocks(reln, forknum));
  #endif

+   if (max_blocks != -1  blocknum  (BlockNumber) max_blocks)
+   ereport(ERROR,
+   (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+errmsg(cannot extend file beyond %u
blocks,
+   max_blocks),
+errhint(Session file limit defined by
\hard_relation_limit\ (%s) is over.,
+
GetConfigOptionByName(hard_relation_limit, NULL;
+





 Should you now be stopped working? Does this feature need to track *who*
 added which chunks of a table (suspect very difficult to do sensibly)?

 Regards

 Mark



Re: [HACKERS] ALTER TABLE lock strength reduction patch is unsafe Reply-To:

2014-03-20 Thread Vik Fearing
On 03/18/2014 11:39 AM, Simon Riggs wrote:
 On 8 March 2014 11:14, Simon Riggs si...@2ndquadrant.com wrote:
 On 7 March 2014 09:04, Simon Riggs si...@2ndquadrant.com wrote:

 The right thing to do here is to not push to the extremes. If we mess
 too much with the ruleutil stuff it will just be buggy. A more
 considered analysis in a later release is required for a full and
 complete approach. As I indicated earlier, an 80/20 solution is better
 for this release.

 Slimming down the patch, I've removed changes to lock levels for
 almost all variants. The only lock levels now reduced are those for
 VALIDATE, plus setting of relation and attribute level options.

 VALIDATE is implemented by calling pg_get_constraintdef_mvcc(), a
 slightly modified variant of pg_get_constraintdef that uses the
 transaction snapshot. I propose this rather than Noah's solution
 solely because this will allow any user to request the MVCC data,
 rather than implement a hack that only works for pg_dump. I will post
 the patch later today.
 Implemented in attached patch, v22

 The following commands (only) are allowed with
 ShareUpdateExclusiveLock, patch includes doc changes.

 ALTER TABLE ... VALIDATE CONSTRAINT constraint_name
 covered by isolation test, plus verified manually with pg_dump

 ALTER TABLE ... ALTER COLUMN ... SET STATISTICS
 ALTER TABLE ... ALTER COLUMN ... SET (...)
 ALTER TABLE ... ALTER COLUMN ... RESET (...)

 ALTER TABLE ... CLUSTER ON ...
 ALTER TABLE ... SET WITHOUT CLUSTER
 ALTER TABLE ... SET (...)
 covered by isolation test

 ALTER TABLE ... RESET (...)

 ALTER INDEX ... SET (...)
 ALTER INDEX ... RESET (...)

 All other ALTER commands take AccessExclusiveLock

 I commend this patch to you for final review; I would like to commit
 this in a few days.
 I'm planning to commit this today at 1500UTC barring objections or
 negative reviews.


At my current level of competence, this patch looks good to me.  I'm
looking forward to reading Noah's review to see what I may have missed.

The attached patch fixes two typos in the code comments.

-- 
Vik

*** a/src/backend/commands/tablecmds.c
--- b/src/backend/commands/tablecmds.c
***
*** 2939,2945  AlterTableGetLockLevel(List *cmds)
  
  /*
   * These subcommands affect implicit row type conversion. They
!  * have affects similar to CREATE/DROP CAST on queries.
   * don't provide for invalidating parse trees as a result of
   * such changes, so we keep these at AccessExclusiveLock.
   */
--- 2939,2945 
  
  /*
   * These subcommands affect implicit row type conversion. They
!  * have affects similar to CREATE/DROP CAST on queries.  We
   * don't provide for invalidating parse trees as a result of
   * such changes, so we keep these at AccessExclusiveLock.
   */
*** a/src/backend/utils/cache/relcache.c
--- b/src/backend/utils/cache/relcache.c
***
*** 1889,1895  RelationDestroyRelation(Relation relation, bool remember_tupdesc)
  	if (--relation-rd_att-tdrefcount == 0)
  	{
  		/*
! 		 * If we Rebuilt a relcache entry during a transaction then its
  		 * possible we did that because the TupDesc changed as the result
  		 * of an ALTER TABLE that ran at less than AccessExclusiveLock.
  		 * It's possible someone copied that TupDesc, in which case the
--- 1889,1895 
  	if (--relation-rd_att-tdrefcount == 0)
  	{
  		/*
! 		 * If we Rebuilt a relcache entry during a transaction then it's
  		 * possible we did that because the TupDesc changed as the result
  		 * of an ALTER TABLE that ran at less than AccessExclusiveLock.
  		 * It's possible someone copied that TupDesc, in which case the

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Review: plpgsql.extra_warnings, plpgsql.extra_errors

2014-03-20 Thread Marko Tiikkaja

On 3/20/14, 12:32 AM, Tom Lane wrote:

Isn't the entire point to create a framework in which more tests will
be added later?

Also, adding GUC_LIST_INPUT later is not really cool since it changes
the parsing behavior for the GUC.  If it's going to be a list, it should
be one from day zero.


I'm not sure what exactly you mean by this.  If the only allowed values 
are none, variable_shadowing and all, how is the behaviour for 
those going to change if we make it a list for 9.5?



Regards,
Marko Tiikkaja


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] four minor proposals for 9.5

2014-03-20 Thread Mark Kirkwood

On 20/03/14 20:08, Pavel Stehule wrote:




2014-03-20 7:25 GMT+01:00 Mark Kirkwood mark.kirkw...@catalyst.net.nz
Also I think this would probably only make sense for TEMPORARY
tables - otherwise you can get this sort of thing going on:

- you create a table and you have set a relation size limit
- you commit and keep working
- I add a whole lot of rows to your new table (taking it over the limit)
- you go to add some more rows to this table...


you cannot to across session limit and is not important if you do
inserts more times or once.



Sorry Pavel - what you have said above is difficult for me to understand 
- if the limit is intended as a *session* limit then concurrent activity 
from multiple sessions makes it behave - well - strangely to say the 
least, as tables are essentially shared resources.


Regards

Mark



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] four minor proposals for 9.5

2014-03-20 Thread Pavel Stehule
2014-03-20 9:47 GMT+01:00 Mark Kirkwood mark.kirkw...@catalyst.net.nz:

 On 20/03/14 20:08, Pavel Stehule wrote:




 2014-03-20 7:25 GMT+01:00 Mark Kirkwood mark.kirkw...@catalyst.net.nz
 Also I think this would probably only make sense for TEMPORARY
 tables - otherwise you can get this sort of thing going on:

 - you create a table and you have set a relation size limit
 - you commit and keep working
 - I add a whole lot of rows to your new table (taking it over the
 limit)
 - you go to add some more rows to this table...


 you cannot to across session limit and is not important if you do
 inserts more times or once.


 Sorry Pavel - what you have said above is difficult for me to understand -
 if the limit is intended as a *session* limit then concurrent activity from
 multiple sessions makes it behave - well - strangely to say the least, as
 tables are essentially shared resources.


I am sorry, I should to explain first our use case. Our product support
multidimensional modelling - usually we have a few (less than 1000)
unlimited user data tables. When  user can to see some view (report), our
engine generate 10 - 100 queries and result of these queries are stored in
tables. Then result of one calculation can be shared between reports,
users. These tables (caches) are semi temporal - life cycle is about hour,
max days. Some queries in multidimensional analysis are Cartesian products
- we are not able to estimate well a sizes of these tables - due free
schema - users can create own logical model (users can fill these data
freely) - and variability of generated queries is too long.

So we need to some safeguards in background.

Regards

Pavel





 Regards

 Mark




Re: [HACKERS] Review: plpgsql.extra_warnings, plpgsql.extra_errors

2014-03-20 Thread Petr Jelinek

On 20/03/14 00:32, Tom Lane wrote:


TBH, if I thought this specific warning was the only one that would ever
be there, I'd probably be arguing to reject this patch altogether.


Of course, nobody assumes that it will be the only one.



Also, adding GUC_LIST_INPUT later is not really cool since it changes
the parsing behavior for the GUC.  If it's going to be a list, it should
be one from day zero.



Actually it does not since it all has to be handled in check/assign hook 
anyway.


But nevertheless, I made V6 with doc change suggested by Alvaro and also 
added this list handling framework for the GUC params.
In the end it is probably less confusing now that the implementation 
uses bitmask instead of bool when the user facing functionality talks 
about list...


This obviously needs code review again (I haven't changed tests since 
nothing changed from user perspective).



--
 Petr Jelinek  http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services
diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml
index bddd458..d1e6c9f 100644
--- a/doc/src/sgml/plpgsql.sgml
+++ b/doc/src/sgml/plpgsql.sgml
@@ -4711,6 +4711,52 @@ a_output := a_output || $$ if v_$$ || referrer_keys.kind || $$ like '$$
   /variablelist
 
   /sect2
+  sect2 id=plpgsql-extra-checks
+   titleAdditional compile-time checks/title
+
+   para
+To aid the user in finding instances of simple but common problems before
+they cause harm, applicationPL/PgSQL/ provides additional
+replaceablechecks/. When enabled, depending on the configuration, they
+can be used to emit either a literalWARNING/ or an literalERROR/
+during the compilation of a function.
+   /para
+
+ para
+  These additional checks are enabled through the configuration variables
+  varnameplpgsql.extra_warnings/ for warnings and 
+  varnameplpgsql.extra_errors/ for errors. Both can be set either to
+  a comma-separated list of checks, literalnone/ or literalall/.
+  The default is literalnone/. Currently the list of available checks
+  includes only one:
+  variablelist
+   varlistentry
+termvarnameshadowed_variables/varname/term
+listitem
+ para
+  Checks if a declaration shadows a previously defined variable. 
+ /para
+/listitem
+   /varlistentry
+  /variablelist
+
+  The following example shows the effect of varnameplpgsql.extra_warnings/
+  set to varnameshadowed_variables/:
+programlisting
+CREATE FUNCTION foo(f1 int) RETURNS int AS $$
+DECLARE
+f1 int;
+BEGIN
+RETURN f1;
+END
+$$ LANGUAGE plpgsql;
+WARNING:  variable f1 shadows a previously defined variable
+LINE 3: f1 int;
+^
+CREATE FUNCTION
+/programlisting
+ /para
+ /sect2
  /sect1
 
   !--  Porting from Oracle PL/SQL  --
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index 5afc2e5..12ac964 100644
--- a/src/pl/plpgsql/src/pl_comp.c
+++ b/src/pl/plpgsql/src/pl_comp.c
@@ -352,6 +352,9 @@ do_compile(FunctionCallInfo fcinfo,
 	function-out_param_varno = -1;		/* set up for no OUT param */
 	function-resolve_option = plpgsql_variable_conflict;
 	function-print_strict_params = plpgsql_print_strict_params;
+	/* only promote extra warnings and errors at CREATE FUNCTION time */
+	function-extra_warnings = forValidator ? plpgsql_extra_warnings : 0;
+	function-extra_errors = forValidator ? plpgsql_extra_errors : 0;
 
 	if (is_dml_trigger)
 		function-fn_is_trigger = PLPGSQL_DML_TRIGGER;
@@ -849,6 +852,9 @@ plpgsql_compile_inline(char *proc_source)
 	function-out_param_varno = -1;		/* set up for no OUT param */
 	function-resolve_option = plpgsql_variable_conflict;
 	function-print_strict_params = plpgsql_print_strict_params;
+	/* don't do extra validation for inline code as we don't want to add spam at runtime */
+	function-extra_warnings = 0;
+	function-extra_errors = 0;
 
 	plpgsql_ns_init();
 	plpgsql_ns_push(func_name);
diff --git a/src/pl/plpgsql/src/pl_gram.y b/src/pl/plpgsql/src/pl_gram.y
index c0cb585..91186c6 100644
--- a/src/pl/plpgsql/src/pl_gram.y
+++ b/src/pl/plpgsql/src/pl_gram.y
@@ -727,6 +727,21 @@ decl_varname	: T_WORD
 			  $1.ident, NULL, NULL,
 			  NULL) != NULL)
 			yyerror(duplicate declaration);
+
+		if (plpgsql_curr_compile-extra_warnings  PLPGSQL_XCHECK_SHADOWVAR ||
+			plpgsql_curr_compile-extra_errors  PLPGSQL_XCHECK_SHADOWVAR)
+		{
+			PLpgSQL_nsitem *nsi;
+			nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
+	$1.ident, NULL, NULL, NULL);
+			if (nsi != NULL)
+ereport(plpgsql_curr_compile-extra_errors  PLPGSQL_XCHECK_SHADOWVAR ? ERROR : WARNING,
+		(errcode(ERRCODE_DUPLICATE_ALIAS),
+		 errmsg(variable \%s\ shadows a previously defined variable,
+$1.ident),
+		 parser_errposition(@1)));
+		}
+
 	}
 | unreserved_keyword
 	{
@@ -740,6 +755,21 @@ decl_varname	: T_WORD
 			  $1, NULL, NULL,
 			  NULL) != NULL)
 			yyerror(duplicate 

Re: [HACKERS] effective_cache_size cannot be changed by a reload

2014-03-20 Thread Fujii Masao
On Thu, Mar 20, 2014 at 2:34 AM, Jeff Janes jeff.ja...@gmail.com wrote:
 In 9.4dev, if the server is started with effective_cache_size = -1, then it
 cannot be changed away from that without a restart.  If you change the
 config file and do a reload or pg_reload_conf(), it ignores the change
 without comment in the logs.

 If you start the server with a value other than -1, then you can change the
 value by editing the file and doing a reload.  You can even change it to -1,
 and then change it back away from -1 again.

I think that's a bug. Patch attached.

 I don't know if bugs reports (without patches) against pre-release versions
 are supposed to go to hackers or to bugs.

Either works at least for me.

Regards,

-- 
Fujii Masao
*** a/src/backend/optimizer/path/costsize.c
--- b/src/backend/optimizer/path/costsize.c
***
*** 4145,4151  set_default_effective_cache_size(void)
  		effective_cache_size = 0;
  		/* and let check_effective_cache_size() compute the setting */
  		SetConfigOption(effective_cache_size, -1,
! 		PGC_POSTMASTER, PGC_S_OVERRIDE);
  	}
  	Assert(effective_cache_size  0);
  }
--- 4145,4151 
  		effective_cache_size = 0;
  		/* and let check_effective_cache_size() compute the setting */
  		SetConfigOption(effective_cache_size, -1,
! 		PGC_POSTMASTER, PGC_S_FILE);
  	}
  	Assert(effective_cache_size  0);
  }

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] jsonb and nested hstore

2014-03-20 Thread Alexander Korotkov
I've noticed two commits on github.

commit b8199ee3c2506ab81b47a0b440363fc90c0d6956
Author: Peter Geoghegan p...@heroku.com
Date:   Wed Mar 19 02:02:16 2014 -0700

For jsonb_hash_ops, hash less

By limiting the GIN entries to the least-nested level, the delicious.com
sample JSON dataset index shrinks in size from 382MB to 255MB without
any apparent downside.

commit 2cea5213dba011625fc0d5c6b447e838080087b1
Author: Peter Geoghegan p...@heroku.com
Date:   Wed Mar 19 02:13:42 2014 -0700

Revert For jsonb_hash_ops, hash less

This might be workable with another approach, but leave it for now. This
reverts commit b8199ee3c2506ab81b47a0b440363fc90c0d6956.

Besides implementation, what the idea was here? For me, it's impossible to
skip any single element, because it's possible for query to include only
this element. If we skip that element, we can't answer corresponding query
no more.

--
With best regards,
Alexander Korotkov.


Re: [HACKERS] inherit support for foreign tables

2014-03-20 Thread Etsuro Fujita

(2014/03/18 18:38), Kyotaro HORIGUCHI wrote:

By the way, Can I have a simple script to build an environment to
run this on?


I built test environment and ran the simple test using
postgres_fdw and got parameterized path from v3 patch on the
following operation as shown there, and v6 also gives one, but I
haven't seen the reparameterization of v6 patch work.

# How could I think to have got it work before?

Do you have any idea to make postgreReparameterizeForeignPath on
foreign (child) tables works effectively?



=# explain analyze select pu1.*
 from pu1 join rpu1 on (pu1.c = rpu1.c) where pu1.a = 3;


ISTM postgresReparameterizeForeignPath() cannot be called in this query 
in principle.  Here is a simple example for the case where the 
use_remote_estimate option is true:


# On mydatabase

mydatabase=# CREATE TABLE mytable (id INTEGER, x INTEGER);
CREATE TABLE
mydatabase=# INSERT INTO mytable SELECT x, x FROM generate_series(0, 
) x;

INSERT 0 1

# On postgres

postgres=# CREATE TABLE inttable (id INTEGER);
CREATE TABLE
postgres=# INSERT INTO inttable SELECT x FROM generate_series(0, ) x;
INSERT 0 1
postgres=# ANALYZE inttable;
ANALYZE

postgres=# CREATE TABLE patest0 (id INTEGER, x INTEGER);
CREATE TABLE
postgres=# CREATE TABLE patest1 () INHERITS (patest0);
CREATE TABLE
postgres=# INSERT INTO patest1 SELECT x, x FROM generate_series(0, ) x;
INSERT 0 1
postgres=# CREATE INDEX patest1_id_idx ON patest1(id);
CREATE INDEX
postgres=# CREATE SERVER myserver FOREIGN DATA WRAPPER postgres_fdw 
OPTIONS (host 'localhost', dbname 'mydatabase');

CREATE SERVER
postgres=# CREATE USER MAPPING FOR PUBLIC SERVER myserver OPTIONS (user 
'pgsql');

CREATE USER MAPPING
postgres=# CREATE FOREIGN TABLE patest2 () INHERITS (patest0) SERVER 
myserver OPTIONS (table_name 'mytable');

CREATE FOREIGN TABLE
postgres=# ANALYZE patest0;
ANALYZE
postgres=# ANALYZE patest1;
ANALYZE
postgres=# ANALYZE patest2;
ANALYZE
postgres=# EXPLAIN VERBOSE SELECT * FROM patest0 join (SELECT id FROM 
inttable LIMIT 1) ss ON patest0.id = ss.id;

   QUERY PLAN
-
 Nested Loop  (cost=0.00..478.36 rows=2 width=12)
   Output: patest0.id, patest0.x, inttable.id
   -  Limit  (cost=0.00..0.01 rows=1 width=4)
 Output: inttable.id
 -  Seq Scan on public.inttable  (cost=0.00..145.00 rows=1 
width=4)

   Output: inttable.id
   -  Append  (cost=0.00..478.31 rows=3 width=8)
 -  Seq Scan on public.patest0  (cost=0.00..0.00 rows=1 width=8)
   Output: patest0.id, patest0.x
   Filter: (inttable.id = patest0.id)
 -  Index Scan using patest1_id_idx on public.patest1 
(cost=0.29..8.30 rows=1 width=8)

   Output: patest1.id, patest1.x
   Index Cond: (patest1.id = inttable.id)
 -  Foreign Scan on public.patest2  (cost=100.00..470.00 
rows=1 width=8)

   Output: patest2.id, patest2.x
   Remote SQL: SELECT id, x FROM public.mytable WHERE 
(($1::integer = id))

 Planning time: 0.233 ms
(17 rows)

I revised the patch.  Patche attached, though I plan to update the 
documentation further early next week.


Thanks,

Best regards,
Etsuro Fujita
*** a/contrib/file_fdw/file_fdw.c
--- b/contrib/file_fdw/file_fdw.c
***
*** 117,122  static void fileGetForeignRelSize(PlannerInfo *root,
--- 117,126 
  static void fileGetForeignPaths(PlannerInfo *root,
RelOptInfo *baserel,
Oid foreigntableid);
+ static ForeignPath *fileReparameterizeForeignPath(PlannerInfo *root,
+   
  RelOptInfo *baserel,
+   
  Path *path,
+   
  Relids required_outer);
  static ForeignScan *fileGetForeignPlan(PlannerInfo *root,
   RelOptInfo *baserel,
   Oid foreigntableid,
***
*** 145,150  static bool check_selective_binary_conversion(RelOptInfo 
*baserel,
--- 149,155 
  static void estimate_size(PlannerInfo *root, RelOptInfo *baserel,
  FileFdwPlanState *fdw_private);
  static void estimate_costs(PlannerInfo *root, RelOptInfo *baserel,
+  List *join_conds,
   FileFdwPlanState *fdw_private,
   Cost *startup_cost, Cost *total_cost);
  static int file_acquire_sample_rows(Relation onerel, int elevel,
***
*** 163,168  file_fdw_handler(PG_FUNCTION_ARGS)
--- 168,174 
  
fdwroutine-GetForeignRelSize = fileGetForeignRelSize;
fdwroutine-GetForeignPaths 

Re: [HACKERS] Portability issues in shm_mq

2014-03-20 Thread Robert Haas
On Tue, Mar 18, 2014 at 4:14 PM, Tom Lane t...@sss.pgh.pa.us wrote:
 Robert Haas robertmh...@gmail.com writes:
 On Tue, Mar 18, 2014 at 12:15 PM, Tom Lane t...@sss.pgh.pa.us wrote:
 Meh.  I think you're putting a bit too much faith in your ability to
 predict the locus of bugs that you think aren't there.

 Well, I'm open to suggestions.

 As a suggestion: it'd be worth explicitly testing zero-byte and one-byte
 messages, those being obvious edge cases.  Then, say, randomly chosen
 lengths in the range 100-1000; this would help ferret out odd-length
 issues.  And something with message sizes larger than the queue size.

All right, done.  Let's see if that tickles any edge cases we haven't
hit before.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Archive recovery won't be completed on some situation.

2014-03-20 Thread Alvaro Herrera
Kyotaro HORIGUCHI escribió:
 Hi, I confirmed that 82233ce7ea4 surely did it.
 
 At Wed, 19 Mar 2014 09:35:16 -0300, Alvaro Herrera wrote
  Fujii Masao escribió:
   On Wed, Mar 19, 2014 at 7:57 PM, Heikki Linnakangas
   hlinnakan...@vmware.com wrote:
  
9.4 canceles backup mode even on immediate shutdown so the
operation causes no problem, but 9.3 and before are doesn't.
   
Hmm, I don't think we've changed that behavior in 9.4.
   
   ISTM 82233ce7ea42d6ba519aaec63008aff49da6c7af changed immdiate
   shutdown that way.
  
  Uh, interesting.  I didn't see that secondary effect.  I hope it's not
  for ill?
 
 The crucial factor for the behavior change is that pmdie has
 become not to exit immediately for SIGQUIT. 'case SIGQUIT:' in
 pmdie() ended with ExitPostmaster(0) before the patch but now
 it ends with 'PostmasterStateMachine(); break;' so continues to
 run with pmState = PM_WAIT_BACKENDS, similar to SIGINT (fast
 shutdown).
 
 After all, pmState changes to PM_NO_CHILDREN via PM_WAIT_DEAD_END
 by SIGCHLDs from non-significant processes, then CancelBackup().

Judging from what was being said on the thread, it seems that running
CancelBackup() after an immediate shutdown is better than not doing it,
correct?

 Focusing on the point described above, the small patch below
 rewinds the behavior back to 9.3 and before but I don't know the
 appropriateness in regard to the intention of the patch.

I see.  Obviously your patch would, in effect, revert 82233ce7ea
completely, which is not something we want.  I think if we want to go
back to the previous behavior of not stopping the backup, some other
method should be used.

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Risk Estimation WAS: Planner hints in Postgresql

2014-03-20 Thread Robert Haas
On Tue, Mar 18, 2014 at 2:41 PM, Tom Lane t...@sss.pgh.pa.us wrote:
 Atri Sharma atri.j...@gmail.com writes:
 One of the factors that leads to bad estimates is that the histogram of the
 values of a column maintained by the planner gets old by time and the data
 in the column changes. So, the histogram is no longer a quite accurate view
 of the data and it leads to bad selectivity.

 TBH, this is so far down the list of problems that it'll be a long time
 before we need to worry about it.  It's certainly not the number one
 priority for any project to model risk in the planner.

 The thing that I think is probably the number one problem is estimates
 that depend on an assumption of uniform distribution of sought-after rows
 among those encountered by a scan.  This is usually where bad plans for
 LIMIT queries are coming from.  We could certainly add some sort of fudge
 factor to those costs, but I'd like to have a more-or-less principled
 framework for doing so.

I think the problem is, in some sense, more basic than that.  I think
the kind of query we're talking about here is:

SELECT * FROM foo WHERE unlikely ORDER BY indexed_column LIMIT 1

Assume for the sake of argument that there are 100 rows that would be
returned in the absence of the limit.  Let SC and TC be the startup
cost and total cost of the index scan.  As a matter of general policy,
we're going to say that the cost of this is SC + 0.01 * (TC - SC).
What makes this path look appealing to the planner is that SC is small
relative to TC.  If we knew, for example, that we weren't going to
find the first match until 90% of the way through the index scan, then
we could set SC = 90% * TC and, all else being equal, the planner
would make the right decision.

So you might think that the problem here is that we're assuming
uniform density.  Let's say there are a million rows in the table, and
there are 100 that match our criteria, so the first one is going to
happen 1/10,000'th of the way through the table.  Thus we set SC =
0.0001 * TC, and that turns out to be an underestimate if the
distribution isn't as favorable as we're hoping.  However, that is NOT
what we are doing.  What we are doing is setting SC = 0.  I mean, not
quite 0, but yeah, effectively 0. Essentially we're assuming that no
matter how selective the filter condition may be, we assume that it
will match *the very first row*.

So we're not assuming the average case and getting hosed when things
come out worse than average.  We're assuming the *best* case.  So
unless things happen to really swing in our favor, we got hosed.

Now it might be that a fudge factor of 2 or 1.5 or 10 or 3 or 17 is
appropriate, so that we actually assume we're going to have to scan a
little more of the index than we expect.  That can perhaps be
justified by the possibility that there may actually be NO rows
matching the filter condition, and we'll have to try scanning the
entire index to get off the ground.  We could also try to come up with
a mathematical model for that.  But that fudge factor would presumably
be a multiplier on the effort of finding the first tuple.  And right
now we assume that finding the first tuple will be trivial.  So I
think we should fix THAT problem first, and then if that turns out to
be insufficient, we can worry about what further fudging is required.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Risk Estimation WAS: Planner hints in Postgresql

2014-03-20 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes:
 So you might think that the problem here is that we're assuming
 uniform density.  Let's say there are a million rows in the table, and
 there are 100 that match our criteria, so the first one is going to
 happen 1/10,000'th of the way through the table.  Thus we set SC =
 0.0001 * TC, and that turns out to be an underestimate if the
 distribution isn't as favorable as we're hoping.  However, that is NOT
 what we are doing.  What we are doing is setting SC = 0.  I mean, not
 quite 0, but yeah, effectively 0. Essentially we're assuming that no
 matter how selective the filter condition may be, we assume that it
 will match *the very first row*.

I think this is wrong.  Yeah, the SC may be 0 or near it, but the time to
fetch the first tuple is estimated as SC + (TC-SC)/N.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Review: plpgsql.extra_warnings, plpgsql.extra_errors

2014-03-20 Thread Tom Lane
Marko Tiikkaja ma...@joh.to writes:
 On 3/20/14, 12:32 AM, Tom Lane wrote:
 Also, adding GUC_LIST_INPUT later is not really cool since it changes
 the parsing behavior for the GUC.  If it's going to be a list, it should
 be one from day zero.

 I'm not sure what exactly you mean by this.  If the only allowed values 
 are none, variable_shadowing and all, how is the behaviour for 
 those going to change if we make it a list for 9.5?

If we switch to using SplitIdentifierString later, which is the typical
implementation of parsing list GUCs, that will do things like case-fold,
remove double quotes, remove white space.  It's possible that that's
completely upward-compatible with what happens if you don't do that ...
but I'm not sure about it.

In any case, if the point of this patch is to provide a framework for
extra error detection, I'm not sure why we'd arbitrarily say we're going
to leave the framework unfinished in the GUC department.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Risk Estimation WAS: Planner hints in Postgresql

2014-03-20 Thread Atri Sharma
On Thu, Mar 20, 2014 at 8:10 PM, Robert Haas robertmh...@gmail.com wrote:

 On Tue, Mar 18, 2014 at 2:41 PM, Tom Lane t...@sss.pgh.pa.us wrote:
  Atri Sharma atri.j...@gmail.com writes:
  One of the factors that leads to bad estimates is that the histogram of
 the
  values of a column maintained by the planner gets old by time and the
 data
  in the column changes. So, the histogram is no longer a quite accurate
 view
  of the data and it leads to bad selectivity.
 
  TBH, this is so far down the list of problems that it'll be a long time
  before we need to worry about it.  It's certainly not the number one
  priority for any project to model risk in the planner.
 
  The thing that I think is probably the number one problem is estimates
  that depend on an assumption of uniform distribution of sought-after rows
  among those encountered by a scan.  This is usually where bad plans for
  LIMIT queries are coming from.  We could certainly add some sort of fudge
  factor to those costs, but I'd like to have a more-or-less principled
  framework for doing so.

 I think the problem is, in some sense, more basic than that.  I think
 the kind of query we're talking about here is:

 SELECT * FROM foo WHERE unlikely ORDER BY indexed_column LIMIT 1

 Assume for the sake of argument that there are 100 rows that would be
 returned in the absence of the limit.  Let SC and TC be the startup
 cost and total cost of the index scan.  As a matter of general policy,
 we're going to say that the cost of this is SC + 0.01 * (TC - SC).
 What makes this path look appealing to the planner is that SC is small
 relative to TC.  If we knew, for example, that we weren't going to
 find the first match until 90% of the way through the index scan, then
 we could set SC = 90% * TC and, all else being equal, the planner
 would make the right decision.

 So you might think that the problem here is that we're assuming
 uniform density.  Let's say there are a million rows in the table, and
 there are 100 that match our criteria, so the first one is going to
 happen 1/10,000'th of the way through the table.  Thus we set SC =
 0.0001 * TC, and that turns out to be an underestimate if the
 distribution isn't as favorable as we're hoping.  However, that is NOT
 what we are doing.  What we are doing is setting SC = 0.  I mean, not
 quite 0, but yeah, effectively 0. Essentially we're assuming that no
 matter how selective the filter condition may be, we assume that it
 will match *the very first row*.



Cannot we reuse the same histogram we have in the planner right now for
this? I mean, AFAIK, the heuristic we have is that we divide the histogram
into equal size buckets and then find the bucket in which our predicate
value lies, then take some part of that bucket and the rest of the buckets
before that bucket,right?

So, suppose a query is SELECT * FROM table WHERE a  10, we shall find the
bucket that 10 lies in, right?

Now, why cannot we take the estimate of all the buckets behind the bucket
in which our value is present? Will that estimate not give us the fraction
of tuples that are expected to be before the first matching row?

Its pretty wild, but I wanted to know if my understanding of this scenario
is correct or not.

Regards,

Atri

-- 
Regards,

Atri
*l'apprenant*


Re: [HACKERS] Risk Estimation WAS: Planner hints in Postgresql

2014-03-20 Thread Tom Lane
Atri Sharma atri.j...@gmail.com writes:
 Now, why cannot we take the estimate of all the buckets behind the bucket
 in which our value is present? Will that estimate not give us the fraction
 of tuples that are expected to be before the first matching row?

Uh, no, not unless you assume that the table happens to be perfectly
sorted by the column's value.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Risk Estimation WAS: Planner hints in Postgresql

2014-03-20 Thread Atri Sharma
On Thu, Mar 20, 2014 at 8:51 PM, Tom Lane t...@sss.pgh.pa.us wrote:

 Atri Sharma atri.j...@gmail.com writes:
  Now, why cannot we take the estimate of all the buckets behind the bucket
  in which our value is present? Will that estimate not give us the
 fraction
  of tuples that are expected to be before the first matching row?

 Uh, no, not unless you assume that the table happens to be perfectly
 sorted by the column's value.




Yes, that is true. So, if an attribute has an index present, can we do this
somehow?

Regards,

Atri



-- 
Regards,

Atri
*l'apprenant*


Re: [HACKERS] effective_cache_size cannot be changed by a reload

2014-03-20 Thread Tom Lane
Fujii Masao masao.fu...@gmail.com writes:
 On Thu, Mar 20, 2014 at 2:34 AM, Jeff Janes jeff.ja...@gmail.com wrote:
 In 9.4dev, if the server is started with effective_cache_size = -1, then it
 cannot be changed away from that without a restart.

 I think that's a bug. Patch attached.

PGC_S_FILE is at least as bogus as the previous choice; for one thing,
such a source setting implies there should be a file and line number
recorded.

I think PGC_S_DYNAMIC_DEFAULT is the right thing, but I've not absorbed
much caffeine yet today.  Also, if that is the right thing, the section of
guc-file.l beginning at about line 284 needs to get taught about it; which
probably means that set_default_effective_cache_size needs a rethink so
that it can be applied and do something useful in that situation.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Re: [COMMITTERS] pgsql: libpq: change PQconndefaults() to ignore invalid service files

2014-03-20 Thread Bruce Momjian
On Sat, Mar  8, 2014 at 08:44:34PM -0500, Bruce Momjian wrote:
 [Just getting back to this.]
 
 Agreed.  I have developed the attached patch which passes the strdup()
 failure up from pg_fe_getauthname() and maps the failure to
 PQconndefaults(), which is now documented as being memory allocation
 failure.
 
 FYI, there was odd coding in PQconndefaults() where we set local
 variable 'name' to NULL, then we tested to see if it was NULL --- I
 removed that test.
 
  idea that we're ignoring failure returns from pqGetpwuid/GetUserName?
 
 If we want pqGetpwuid/GetUserName to be a special return value, we would
 need to modify PQconndefaults()'s API, which doesn't seem worth it.

Applied.  I added a C comment about why we ignore pqGetpwuid/GetUserName
failures.

-- 
  Bruce Momjian  br...@momjian.ushttp://momjian.us
  EnterpriseDB http://enterprisedb.com

  + Everyone has their own god. +


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Risk Estimation WAS: Planner hints in Postgresql

2014-03-20 Thread Robert Haas
On Thu, Mar 20, 2014 at 10:45 AM, Tom Lane t...@sss.pgh.pa.us wrote:
 Robert Haas robertmh...@gmail.com writes:
 So you might think that the problem here is that we're assuming
 uniform density.  Let's say there are a million rows in the table, and
 there are 100 that match our criteria, so the first one is going to
 happen 1/10,000'th of the way through the table.  Thus we set SC =
 0.0001 * TC, and that turns out to be an underestimate if the
 distribution isn't as favorable as we're hoping.  However, that is NOT
 what we are doing.  What we are doing is setting SC = 0.  I mean, not
 quite 0, but yeah, effectively 0. Essentially we're assuming that no
 matter how selective the filter condition may be, we assume that it
 will match *the very first row*.

 I think this is wrong.  Yeah, the SC may be 0 or near it, but the time to
 fetch the first tuple is estimated as SC + (TC-SC)/N.

Hmm, you're right, and experimentation confirms that the total cost of
the limit comes out to about TC/selectivity.  So scratch that theory.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Alexandr

Hello!
Here is the text of my proposal which I've applied to GSoC.
(and link 
https://docs.google.com/document/d/1vBjQzhFT_fgoIkoEP5TVeyFA6ggsYlLq76tghGVUD6A/edit?usp=sharing)

Any suggestions and comments are welcome.
Because I don't know the code of PostgreSQL well I decide not to 
participate is QSoC with previous proposal (rewrite pg_dump and 
pg_restore as libraries). But I'm very interested to participate in QSoC 
2014 as a part of PostgreSQL. So It's my new proposal.


*

PostgreSQL GSoC 2014 proposal

Project name

date_trunc() supporting intervals

Short description

The function date_trunc () is conceptually similar to the trunc function 
for numbers. But now it doesn’t have full functionality because 
intervals are not supporting intervals in date_trunc ().


Name: Alexander Shvidchenko

E-mail: askel...@gmail.com mailto:askel...@gmail.com

Location: Rostov-on-Don, Russia (UTC +04.00)

Benefits to the PostgreSQL Community

This feature will expand opportunities to work with time in databases. 
It will do the job with time more flexible and easier.


Quantifiable results

Supporting and correct working with intervals by date_trunc ()

Project Schedule

until May 31

Make code review and solve architecture questions with help of community

1 June – 30 June

Detailed implementation of libraries.

1 July – 31 July

Finish Implementation of libraires and begin testing.

1 August -15 August

Final refactoring, testing and commit.

Some details

In the period until May 31 I need to discover what types of intervals 
are able to be sent. Also I need to set the stamp of the result.


For example:

date_trunc (‘week’, ‘1 month 15 day’:interval)

result

‘1 month 14 day’

or

‘1 month 2 week’

It seems like this project idea isn’t very difficult and large. So if I 
have time after finishing this job I’ll be able to work more: close some 
bugs or realize some more features that will be usefull for the community.


Academic experience

I entered the university in 2013. Before entering the university I 
finished the college in 2012. My graduate work in the college was the 
client-server application. It was a realization of XMPP. The client was 
realized in Qt. The client worked with SQLite database and the server 
worked with MySQL database.


Why is PostgreSQL?

- I’m intereted in this idea and believe this project would be useful 
for the community;


- PostgreSQL is a very respected community. I would be proud to be a 
part of it;


- PostgreSQL is one of the best DBMS and I would like to make it better.

Links

1) PostgreSQL 9.3.3 Documentation, date_trunc

http://www.postgresql.org/docs/9.3/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC

*
With best wishes,
Alexander S.


[HACKERS]

2014-03-20 Thread Rajashree Mandaogane
While debugging any function in PostgreSQL, whenever I use the command
'bt', it doesn't give the entire list of functions used. Which command
should be used instead?


Re: [HACKERS]

2014-03-20 Thread Tom Lane
Rajashree Mandaogane rajashree@gmail.com writes:
 While debugging any function in PostgreSQL, whenever I use the command
 'bt', it doesn't give the entire list of functions used. Which command
 should be used instead?

It's probably omitting functions that have been inlined; if so, the fix
is to recompile with a lower -O level to prevent inlining.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] jsonb and nested hstore

2014-03-20 Thread Peter Geoghegan
On Thu, Mar 20, 2014 at 5:32 AM, Alexander Korotkov
aekorot...@gmail.com wrote:
 Besides implementation, what the idea was here? For me, it's impossible to
 skip any single element, because it's possible for query to include only
 this element. If we skip that element, we can't answer corresponding query
 no more.

This had something to do with an alternative notion of containment. I
wouldn't have stuck with such a radical change without consulting you.
I reverted it, and am not going to argue for the idea right now.


-- 
Peter Geoghegan


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] GSoC 2014 - mentors, students and admins

2014-03-20 Thread Thom Brown
Hi all,

There is 1 day left to get submissions in, so students should ensure
that they submit their proposals as soon as possible.  No submissions
will be accepted beyond the deadline of 19:00 UTC tomorrow (Friday
21st March).

Regards

Thom


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] GSoC application: MADlib k-medoids clustering

2014-03-20 Thread Maxence Ahlouche
Hi,

My proposal is now available on Google melange website:
http://www.google-melange.com/gsoc/proposal/public/google/gsoc2014/viod/5668600916475904
There seems to be a formatting issue: half of the text is a link to the
page I mentionned during my registration on my website. I don't know how to
fix it though.

Regards,
Maxence

-- 
Maxence Ahlouche
06 06 66 97 00


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Josh Berkus
On 03/20/2014 09:56 AM, Alexandr wrote:
 Here is the text of my proposal which I've applied to GSoC.
 (and link
 https://docs.google.com/document/d/1vBjQzhFT_fgoIkoEP5TVeyFA6ggsYlLq76tghGVUD6A/edit?usp=sharing)
 
 Any suggestions and comments are welcome.
 Because I don't know the code of PostgreSQL well I decide not to
 participate is QSoC with previous proposal (rewrite pg_dump and
 pg_restore as libraries). But I'm very interested to participate in QSoC
 2014 as a part of PostgreSQL. So It's my new proposal.

Per my comments on the GSOC app, it looks good, but I'd like to see some
stretch goals if you are able to implement the new function before
GSOC is over.  For example, one thing which has been frequently
requested is functions to display intervals in the unit of your choice
... for example, convert 1 day to 14400 seconds.

Pick some stretch goals which work for you ... but I'd like to see some.

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] HEAD seems to generate larger WAL regarding GIN index

2014-03-20 Thread Jesper Krogh

On 15/03/14 20:27, Heikki Linnakangas wrote:
That said, I didn't expect the difference to be quite that big when 
you're appending to the end of the table. When the new entries go to 
the end of the posting lists, you only need to recompress and WAL-log 
the last posting list, which is max 256 bytes long. But I guess that's 
still a lot more WAL than in the old format.


That could be optimized, but I figured we can live with it, thanks to 
the fastupdate feature. Fastupdate allows amortizing that cost over 
several insertions. But of course, you explicitly disabled that...


In a concurrent update environment, fastupdate as it is in 9.2 is not 
really useful. It may be that you can bulk up insertion, but you have no 
control over who ends up paying the debt. Doubling the amount of wal 
from gin-indexing would be pretty tough for us, in 9.2 we generate 
roughly 1TB wal / day, keeping it
for some weeks to be able to do PITR. The wal are mainly due to 
gin-index updates as new data is added and needs to be searchable by 
users. We do run gzip that cuts it down to 25-30% before keeping the for 
too long, but doubling this is going to be a migration challenge.


If fast-update could be made to work in an environment where we both 
have users searching the index and manually updating it and 4+ backend 
processes updating the index concurrently then it would be a good 
benefit to gain.


the gin index currently contains 70+ million records with and average 
tsvector of 124 terms.


--
Jesper .. trying to add some real-world info.




- Heikki






--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Thom Brown
On 20 March 2014 20:07, Josh Berkus j...@agliodbs.com wrote:
 On 03/20/2014 09:56 AM, Alexandr wrote:
 Here is the text of my proposal which I've applied to GSoC.
 (and link
 https://docs.google.com/document/d/1vBjQzhFT_fgoIkoEP5TVeyFA6ggsYlLq76tghGVUD6A/edit?usp=sharing)

 Any suggestions and comments are welcome.
 Because I don't know the code of PostgreSQL well I decide not to
 participate is QSoC with previous proposal (rewrite pg_dump and
 pg_restore as libraries). But I'm very interested to participate in QSoC
 2014 as a part of PostgreSQL. So It's my new proposal.

 Per my comments on the GSOC app, it looks good, but I'd like to see some
 stretch goals if you are able to implement the new function before
 GSOC is over.  For example, one thing which has been frequently
 requested is functions to display intervals in the unit of your choice
 ... for example, convert 1 day to 14400 seconds.

+1

This is definitely something I've wanted in the past, like getting the
number of minutes between 2 timestamps without converting to seconds
since epoch then doing a subtraction.

like:

date_diff(timestamptz, timestamptz, interval) returns decimal

# SELECT date_diff('2014-02-04 12:44:18+0'::timestamptz, '2014-02-08
20:10:05+0'::timestamptz, '1 second');
 date_diff
---
372347
(1 row)

# SELECT date_diff('2014-02-04 12:44:18+0'::timestamptz, '2014-02-08
20:10:05+0'::timestamptz, '5 seconds');
 date_diff
---
 74469
(1 row)

# SELECT date_diff('2014-02-04 12:44:18+0'::timestamptz, '2014-02-08
20:10:05+0'::timestamptz, '1 day');
 date_diff

 4.3095717592592593
(1 row)


Although perhaps there's a more flexible and useful way of doing this
that.  One would probably want to convert an interval to such units
too, like '3 days' in seconds.

-- 
Thom


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Alexandr


21.03.2014 00:07, Josh Berkus пишет:
Per my comments on the GSOC app, it looks good, but I'd like to see 
some stretch goals if you are able to implement the new function 
before GSOC is over. For example, one thing which has been frequently 
requested is functions to display intervals in the unit of your choice 
... for example, convert 1 day to 14400 seconds. Pick some stretch 
goals which work for you ... but I'd like to see some. 

I looked through TODO and found only 2 ideas with intervals:
1) Allow infinite intervals just like infinite timestamps
2) Have timestamp subtraction not call justify_hours() (formatting 
intervals with to_chars)

I want to add these ideas as stretch goals:
1) extract_total() - allows conversation of the interval to a total 
number of the user's desired unit

2) Allow TIMESTAMP WITH TIME ZONE
3) add function to allow the creation of timestamps using parameters
4) Add function to detect if an array is empty
Josh, what do you think about them?


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Josh Berkus
On 03/20/2014 01:26 PM, Alexandr wrote:
 
 21.03.2014 00:07, Josh Berkus пишет:
 Per my comments on the GSOC app, it looks good, but I'd like to see
 some stretch goals if you are able to implement the new function
 before GSOC is over. For example, one thing which has been frequently
 requested is functions to display intervals in the unit of your choice
 ... for example, convert 1 day to 14400 seconds. Pick some stretch
 goals which work for you ... but I'd like to see some. 
 I looked through TODO and found only 2 ideas with intervals:
 1) Allow infinite intervals just like infinite timestamps
 2) Have timestamp subtraction not call justify_hours() (formatting
 intervals with to_chars)
 I want to add these ideas as stretch goals:
 1) extract_total() - allows conversation of the interval to a total
 number of the user's desired unit
 2) Allow TIMESTAMP WITH TIME ZONE
 3) add function to allow the creation of timestamps using parameters
 4) Add function to detect if an array is empty
 Josh, what do you think about them?

Comments:
#2: I don't understand this one?

#3 is already a patch for version 9.4, but possibly you can
improve/expand it.

#4 has already been the subject of a LOT of debate, I think you don't
want to get into it.

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Steve Atkins

On Mar 20, 2014, at 1:24 PM, Thom Brown t...@linux.com wrote:

 On 20 March 2014 20:07, Josh Berkus j...@agliodbs.com wrote:
 On 03/20/2014 09:56 AM, Alexandr wrote:
 Here is the text of my proposal which I've applied to GSoC.
 (and link
 https://docs.google.com/document/d/1vBjQzhFT_fgoIkoEP5TVeyFA6ggsYlLq76tghGVUD6A/edit?usp=sharing)
 
 Any suggestions and comments are welcome.
 Because I don't know the code of PostgreSQL well I decide not to
 participate is QSoC with previous proposal (rewrite pg_dump and
 pg_restore as libraries). But I'm very interested to participate in QSoC
 2014 as a part of PostgreSQL. So It's my new proposal.
 
 Per my comments on the GSOC app, it looks good, but I'd like to see some
 stretch goals if you are able to implement the new function before
 GSOC is over.  For example, one thing which has been frequently
 requested is functions to display intervals in the unit of your choice
 ... for example, convert 1 day to 14400 seconds.
 
 +1
 
 This is definitely something I've wanted in the past, like getting the
 number of minutes between 2 timestamps without converting to seconds
 since epoch then doing a subtraction.

It’d be nice, but isn’t it impossible with anything similar to the existing 
interval
type (as you lose data when you convert to an interval that you can’t get back)?

Subtracting to get an interval, then converting that interval to seconds or 
minutes
could give you a value that’s wildly different from the right answer.

Cheers,
  Steve



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Alexandr


21.03.2014 00:33, Josh Berkus пишет:

Comments:
#2: I don't understand this one?
#3 is already a patch for version 9.4, but possibly you can 
improve/expand it.
#4 has already been the subject of a LOT of debate, I think you don't 
want to get into it. 
I meaned this one: Allow TIMESTAMP WITH TIME ZONE to store the original 
timezone information, either zone name or offset from UTC

And which ideas can you advise me to add to proposal?

With best wishes,
Alexander S.


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Josh Berkus

 I meaned this one: Allow TIMESTAMP WITH TIME ZONE to store the original
 timezone information, either zone name or offset from UTC
 And which ideas can you advise me to add to proposal?

That one has also been hotly debated.  You'd probably have to do it as
an extension, and that would be a fairly large stretch goal.

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Alvaro Herrera
Alexandr escribió:
 
 21.03.2014 00:33, Josh Berkus пишет:
 Comments:
 #2: I don't understand this one?
 #3 is already a patch for version 9.4, but possibly you can
 improve/expand it.
 #4 has already been the subject of a LOT of debate, I think you
 don't want to get into it.
 I meaned this one: Allow TIMESTAMP WITH TIME ZONE to store the
 original timezone information, either zone name or offset from UTC
 And which ideas can you advise me to add to proposal?

This has been discussed previously.  I doubt it makes a good GSoC
project.  Maybe if you were to create a new datatype that stored the
timestamptz plus the original timezone separately, it'd work better;
however I vaguely remember we discussed this a long time ago.  One of
the challenges was how to store the timezone; we didn't want to spend as
much as the whole text representation, so we wanted a catalog that
attached an OID to each timezone. It got real messy from there, and we
dropped the idea.

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Alexandr


Subtracting to get an interval, then converting that interval to 
seconds or minutes could give you a value that’s wildly different from 
the right answer. 

Can you explain me when it happens ?


With best wishes,
Alexander S.


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: date_trunc supporting intervals

2014-03-20 Thread Claudio Freire
On Thu, Mar 20, 2014 at 5:55 PM, Alexandr askel...@gmail.com wrote:
 Subtracting to get an interval, then converting that interval to seconds
 or minutes could give you a value that's wildly different from the right
 answer.

 Can you explain me when it happens ?


'1 month'::interval

It's different depending on which month we're talking about.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Array of composite types returned from python

2014-03-20 Thread Behn, Edward (EBEHN)
I've endeavored to enable the return of arrays of composite types from code
written in PL/Python.  It seems that this can be accomplished though a very
minor change to the code:

 

On line 401 in the file src/pl/plpython/plpy_typeio.c, remove the error
report PL/Python functions cannot return type. and replace it with the
command 

arg-func = PLyObject_ToComposite; 

 

From all that I can see, this does exactly what I want. A python list of
tuples is converted to an array of composite types in SQL. 

 

I ran the main and python regression suites for both python2 and python3
with assert enabled. The only discrepancies I got were ones that were due to
the output expecting an error. When I altered the .out files to the expected
behavior, it matched just fine. 

 

Am I missing anything, (ie memory leak, undesirable behavior elsewhere)? 

 -Ed 

 

 

Ed Behn / Staff Engineer / Airline and Network Services
Information Management Services
2551 Riva Road, Annapolis, MD 21401 USA
Phone: 410.266.4426 / Cell: 240.696.7443
eb...@arinc.com
 http://www.rockwellcollins.com/ www.rockwellcollins.com



 

image001.pngimage002.png

smime.p7s
Description: S/MIME cryptographic signature


Re: [HACKERS] QSoC proposal: Rewrite pg_dump and pg_restore

2014-03-20 Thread Robert Haas
On Tue, Mar 18, 2014 at 8:41 PM, Alexandr askel...@gmail.com wrote:
 Rewrite (add) pg_dump and pg_restore utilities as libraries (.so, .dll 
 .dylib)

This strikes me as (1) pretty vague and (2) probably too hard for a
summer project.

I mean, getting the existing binaries to build libraries that you can
call with some trivial interface that mimics the existing command-line
functionality of pg_dump might be doable, but that's not all that
interesting.  What people are really going to want is a library with a
sophisticated API that lets you do interesting things
programmatically.  But that's going to be hard.  AFAIK, nobody's even
tried to figure out what that API should look like.  Even if we had
that worked out, a non-trivial task, the pg_dump source code is a
mess, so refactoring it to provide such an API is likely to be a job
and a half.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS]

2014-03-20 Thread Craig Ringer
On 03/21/2014 01:12 AM, Tom Lane wrote:
 Rajashree Mandaogane rajashree@gmail.com writes:
 While debugging any function in PostgreSQL, whenever I use the command
 'bt', it doesn't give the entire list of functions used. Which command
 should be used instead?
 
 It's probably omitting functions that have been inlined; if so, the fix
 is to recompile with a lower -O level to prevent inlining.

For more details, see
https://wiki.postgresql.org/wiki/Developer_FAQ#What_debugging_features_are_available.3F
.

If you want to completely prevent inlining you can use -O0 instead of -Og .


-- 
 Craig Ringer   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: Rewrite pg_dump and pg_restore

2014-03-20 Thread Craig Ringer
On 03/21/2014 09:28 AM, Robert Haas wrote:
 On Tue, Mar 18, 2014 at 8:41 PM, Alexandr askel...@gmail.com wrote:
 Rewrite (add) pg_dump and pg_restore utilities as libraries (.so, .dll 
 .dylib)
 
 This strikes me as (1) pretty vague and (2) probably too hard for a
 summer project.
 
 I mean, getting the existing binaries to build libraries that you can
 call with some trivial interface that mimics the existing command-line
 functionality of pg_dump might be doable, but that's not all that
 interesting.  What people are really going to want is a library with a
 sophisticated API that lets you do interesting things
 programmatically.  But that's going to be hard.  AFAIK, nobody's even
 tried to figure out what that API should look like.  Even if we had
 that worked out, a non-trivial task, the pg_dump source code is a
 mess, so refactoring it to provide such an API is likely to be a job
 and a half.

... and still wouldn't solve one of the most frequently requested things
for pg_dump / pg_restore, which is the ability to use them *server-side*
over a regular PostgreSQL connection. It'd be useful progress toward
that, though.

Right now, we can't even get the PostgreSQL server to emit DDL for a
table, let alone do anything more sophisticated.

Here's how I think it needs to look:

- Design a useful API for pg_dump and pg_restore that is practical to
  use for pg_dump and pg_restore's current tasks (fast database
  dump/restore) and also useful for extracting specific objects
  from the database. When designing, consider that we'll want to
  expose this API or functions that use it over SQL later.

- Create a new libpqdump library.

- Implement the designed API in the new library, moving and
  adjusting code from pg_dump / pg_restore where possible, writing
  new code where not.

- Refactor (closer to rewrite) pg_dump and pg_restore to use libpqdump,
  removing as much knowledge of the system catalogs etc as possible from
  them.

- Make sure the result still performs OK

THEN, once that's settled in:

- Modify libpqdump to support compilation as a backend extension, with
  use of the SPI for queries and use of syscaches or direct scans
  where possible.

- Write a pg_dump extension that uses libpqdump in SPI mode
  to expose its API over SQL, or at least uses it to provide SQL
  functions to describe database objects. So you can dump a DB,
  or a subset of it, over SQL.

After all, a libpgdump won't do much good for the large proportion of
PostgreSQL users who use Java/JDBC, who can't use a native library
(without hideous hacks with JNI). For the very large group who use libpq
via language-specific client interfaces like the Pg gem for Ruby,
psycopg2 for Python, DBD::Pg for Perl, etc, it'll require a lot of work
to wrap the API and maintain it. Wheras a server-side SQL-callable
interface would be useful and immediately usable for all of them.

-- 
 Craig Ringer   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: Rewrite pg_dump and pg_restore

2014-03-20 Thread Tom Lane
Craig Ringer cr...@2ndquadrant.com writes:
 Here's how I think it needs to look:
 [ move all the functionality to the backend ]

Of course, after you've done all that work, you've got something that is
of exactly zero use to its supposed principal use-case, pg_dump.  pg_dump
will still have to support server versions that predate all these fancy
new dump functions, and that pretty much ensures that most of pg_dump's
core functionality will still be on the client side.  Or, if you try to
finesse that problem by making sure the new server APIs correspond to
easily-identified pieces of pg_dump code, you'll probably end up with APIs
that nobody else wants to use :-(.

In any case, I quite agree with the sentiment that this is not a suitable
problem for a GSOC project.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] QSoC proposal: Rewrite pg_dump and pg_restore

2014-03-20 Thread Craig Ringer
On 03/21/2014 11:09 AM, Tom Lane wrote:
 Craig Ringer cr...@2ndquadrant.com writes:
 Here's how I think it needs to look:
 [ move all the functionality to the backend ]
 
 Of course, after you've done all that work, you've got something that is
 of exactly zero use to its supposed principal use-case, pg_dump.  pg_dump
 will still have to support server versions that predate all these fancy
 new dump functions, and that pretty much ensures that most of pg_dump's
 core functionality will still be on the client side.  Or, if you try to
 finesse that problem by making sure the new server APIs correspond to
 easily-identified pieces of pg_dump code, you'll probably end up with APIs
 that nobody else wants to use :-(.

Yeah, that's why it's necessary to create a libpqdump that's usable
client-side even if you want server-side dump support.

So it's allow the functionality to be used from the backend as well,
not just move all the functionality to the backend.

-- 
 Craig Ringer   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] ALTER TABLE lock strength reduction patch is unsafe Reply-To:

2014-03-20 Thread Noah Misch
On Sat, Mar 08, 2014 at 11:14:30AM +, Simon Riggs wrote:
 On 7 March 2014 09:04, Simon Riggs si...@2ndquadrant.com wrote:
  The right thing to do here is to not push to the extremes. If we mess
  too much with the ruleutil stuff it will just be buggy. A more
  considered analysis in a later release is required for a full and
  complete approach. As I indicated earlier, an 80/20 solution is better
  for this release.
 
  Slimming down the patch, I've removed changes to lock levels for
  almost all variants. The only lock levels now reduced are those for
  VALIDATE, plus setting of relation and attribute level options.

Good call.

 The following commands (only) are allowed with
 ShareUpdateExclusiveLock, patch includes doc changes.
 
 ALTER TABLE ... VALIDATE CONSTRAINT constraint_name
 covered by isolation test, plus verified manually with pg_dump

I found a pre-existing bug aggravated by this, which I will shortly report on
a new thread.

 ALTER TABLE ... ALTER COLUMN ... SET STATISTICS
 ALTER TABLE ... ALTER COLUMN ... SET (...)
 ALTER TABLE ... ALTER COLUMN ... RESET (...)
 
 ALTER TABLE ... CLUSTER ON ...
 ALTER TABLE ... SET WITHOUT CLUSTER

A comment at check_index_is_clusterable() still mentions exclusive lock.

 ALTER TABLE ... SET (...)
 covered by isolation test
 
 ALTER TABLE ... RESET (...)
 
 ALTER INDEX ... SET (...)
 ALTER INDEX ... RESET (...)

See discussion below.

 All other ALTER commands take AccessExclusiveLock

 --- a/doc/src/sgml/mvcc.sgml
 +++ b/doc/src/sgml/mvcc.sgml
 @@ -865,7 +865,8 @@ ERROR:  could not serialize access due to read/write 
 dependencies among transact
  para
   Acquired by commandVACUUM/command (without 
 optionFULL/option),
   commandANALYZE/, commandCREATE INDEX CONCURRENTLY/, and
 - some forms of commandALTER TABLE/command.
 + commandALTER TABLE VALIDATE/command and other
 + commandALTER TABLE/command variants that set options.

ALTER TABLE's documentation covers the details, so the old text sufficed for
here.  I find variants that set options too vague, considering the nuances
of the actual list of affected forms.

  /para
 /listitem
/varlistentry
 @@ -951,7 +952,7 @@ ERROR:  could not serialize access due to read/write 
 dependencies among transact
  /para
  
  para
 - Acquired by the commandALTER TABLE/, commandDROP TABLE/,
 + Acquired by the commandALTER TABLE/ for rewriting, 
 commandDROP TABLE/,
   commandTRUNCATE/command, commandREINDEX/command,
   commandCLUSTER/command, and commandVACUUM FULL/command
   commands.

Forms that rewrite the table are just one class of examples.  I would write
Acquired by DROP TABLE, ..., VACUUM FULL, and some forms of ALTER TABLE.

 --- a/doc/src/sgml/ref/alter_table.sgml
 +++ b/doc/src/sgml/ref/alter_table.sgml

 @@ -420,6 +439,9 @@ ALTER TABLE [ IF EXISTS ] replaceable 
 class=PARAMETERname/replaceable
index specification from the table.  This affects
future cluster operations that don't specify an index.
   /para
 + para
 +  Changing cluster options uses a literalSHARE UPDATE 
 EXCLUSIVE/literal lock.
 + /para
  /listitem
 /varlistentry
  
 @@ -467,6 +489,10 @@ ALTER TABLE [ IF EXISTS ] replaceable 
 class=PARAMETERname/replaceable
FULL/, xref linkend=SQL-CLUSTER or one of the forms
of commandALTER TABLE/ that forces a table rewrite.
   /para
 + para
 +  Changing storage parameters requires only a
 +  literalSHARE UPDATE EXCLUSIVE/literal lock.
 + /para

Some places say requires only, while others say uses.  Please adopt one of
those consistently.  I somewhat prefer the latter.

 @@ -1075,6 +1105,14 @@ ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN 
 KEY (address) REFERENCES
/para
  
para
 +   To add a foreign key constraint to a table minimising impact on other 
 work:

Our documentation has used the minimize spelling exclusively.

 --- a/src/backend/catalog/toasting.c
 +++ b/src/backend/catalog/toasting.c

 @@ -52,7 +53,7 @@ static bool needs_toast_table(Relation rel);
   * to end with CommandCounterIncrement if it makes any changes.
   */
  void
 -AlterTableCreateToastTable(Oid relOid, Datum reloptions)
 +AlterTableCreateToastTable(Oid relOid, Datum reloptions, LOCKMODE lockmode)
  {
   Relationrel;
  
 @@ -63,10 +64,10 @@ AlterTableCreateToastTable(Oid relOid, Datum reloptions)
* concurrent readers of the pg_class tuple won't have visibility 
 issues,
* so let's be safe.
*/

The comment ending right here is falsified by the change.

 - rel = heap_open(relOid, AccessExclusiveLock);
 + rel = heap_open(relOid, lockmode);

We now request whatever lock our caller has already taken.  If that is
AccessExclusiveLock, create_toast_table() could actually add a toast table.
Otherwise, it will either deduce that no change is required or raise an error.

 @@ 

[HACKERS] equalTupleDescs() ignores ccvalid/ccnoinherit

2014-03-20 Thread Noah Misch
We added these ConstrCheck fields for 9.2, but equalTupleDescs() did not get
the memo.  I looked for resulting behavior problems, and I found one in
RelationClearRelation() only.  Test case:

set constraint_exclusion = on;
drop table if exists ccvalid_test;
create table ccvalid_test (c int);
alter table ccvalid_test add constraint x check (c  0) not valid;

begin;
-- constraint_exclusion won't use an invalid constraint.
explain (costs off) select * from ccvalid_test where c = 0;
-- Make it valid.
alter table ccvalid_test validate constraint x;
-- Local invalidation rebuilt the Relation and decided the TupleDesc hadn't
-- changed, so we're still not using the constraint.
explain (costs off) select * from ccvalid_test where c = 0;
commit;

-- At COMMIT, we destroyed the then-closed Relation in response to shared
-- invalidation.  Now constraint_exclusion sees the valid constraint.
explain (costs off) select * from ccvalid_test where c = 0;


Currently, the damage is limited to later commands in the transaction that
issued ALTER TABLE VALIDATE.  Changing ccvalid requires AccessExclusiveLock,
so no other backend will have an affected, open relcache entry to rebuild.
Shared invalidation will make the current backend destroy its affected
relcache entry before starting a new transaction.  However, the impact will
not be so limited once we allow ALTER TABLE VALIDATE to run with a mere
ShareUpdateExclusiveLock.  (I discovered this bug while reviewing the patch
implementing that very feature.)

I don't see a way to get trouble from the ccnoinherit omission.  You can't
change ccnoinherit except by dropping and recreating the constraint, and each
of the drop and create operations would make equalTupleDescs() detect a
change.  The same can be said of ccbin, but equalTupleDescs() does compare
that field.  For simplicity, I'll have it compare ccnoinherit.

CreateTupleDescCopyConstr() also skips ccnoinherit.  I don't see a resulting
live bug, but it's worth correcting.

Given the minor symptoms in released versions, I lean against a back-patch.

Thanks,
nm

-- 
Noah Misch
EnterpriseDB http://www.enterprisedb.com
diff --git a/src/backend/access/common/tupdesc.c 
b/src/backend/access/common/tupdesc.c
index db8cb82..74cfb64 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -204,6 +204,7 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
if (constr-check[i].ccbin)
cpy-check[i].ccbin = 
pstrdup(constr-check[i].ccbin);
cpy-check[i].ccvalid = 
constr-check[i].ccvalid;
+   cpy-check[i].ccnoinherit = 
constr-check[i].ccnoinherit;
}
}
 
@@ -458,7 +459,9 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
for (j = 0; j  n; check2++, j++)
{
if (strcmp(check1-ccname, check2-ccname) == 0 

-   strcmp(check1-ccbin, check2-ccbin) == 
0)
+   strcmp(check1-ccbin, check2-ccbin) == 
0 
+   check1-ccvalid == check2-ccvalid 
+   check1-ccnoinherit == 
check2-ccnoinherit)
break;
}
if (j = n)

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Optimized out tags

2014-03-20 Thread Rajashree Mandaogane
What can be done to get rid of the 'optimized out' tags while debugging?


Re: [HACKERS] Optimized out tags

2014-03-20 Thread Atri Sharma
On Fri, Mar 21, 2014 at 9:49 AM, Rajashree Mandaogane 
rajashree@gmail.com wrote:

 What can be done to get rid of the 'optimized out' tags while debugging?


Did you use the appropriate debugging flags when running ./configure?

Regards,

Atri
-- 
Regards,

Atri
*l'apprenant*