Thread: How do I save my tables?

How do I save my tables?

From
Kimberly Israel
Date:
I'm brand-new to database building (though I've worked with already-built databases running queries and such).  I'm trying to build a database for some ecological data.  I'm working in pgAdmin III and am comfortable with using SQL queries to create and populate the tables.  What I don't understand is how to save the tables.  Yesterday I created several tables and was able to run queries that combined data from more than one table at a time, but when I reopened pgAdmin III today, the database I had created was there, but the tables were all gone.  I tried to save my work, but what got saved was a .sql file that seems to only contain the code for creating the database.  Basically what I need to know is how do I put my tables somewhere where I'll be able to continue working with them after a 
period of having the computer off?

I'm running "PostgreSQL 9.3.0, compiled by Visual C++ build 1600, 32-bit" and I installed it with the EnterpriseDB installer.  I used all the default settings in the setup.  

My OS is Windows 7 Home Premium, Version 6.1 (Build 7601: Service Pack 1).

I realize this is probably an extremely stupid question; I haven't been able to find anything on a level that I can understand.  I really appreciate any help you can provide.

Thanks,
Kimberly Israel

P.S. My log from yesterday is below.  I don't know if it'll be of any help, but just in case.  A lot of the errors are just me stumbling around figuring things out.

2013-09-16 11:32:55 EDT LOG:  database system was shut down at 2013-09-16 11:32:40 EDT
2013-09-16 11:32:55 EDT LOG:  database system is ready to accept connections
2013-09-16 11:32:55 EDT LOG:  autovacuum launcher started
2013-09-16 12:29:37 EDT LOG:  could not receive data from client: No connection could be made because the target machine actively refused it.

2013-09-16 12:39:11 EDT FATAL:  password authentication failed for user "Main"
2013-09-16 12:39:11 EDT DETAIL:  Connection matched pg_hba.conf line 82: "host    all             all             ::1/128                 md5"
2013-09-16 12:39:22 EDT FATAL:  password authentication failed for user "Main"
2013-09-16 12:39:22 EDT DETAIL:  Connection matched pg_hba.conf line 82: "host    all             all             ::1/128                 md5"
2013-09-16 12:41:20 EDT ERROR:  syntax error at or near "pg_restore" at character 1
2013-09-16 12:41:20 EDT STATEMENT:  pg_restore
-U postgres
-d dvdrental C:
SELECT version();
2013-09-16 12:47:20 EDT LOG:  could not receive data from client: No connection could be made because the target machine actively refused it.

2013-09-16 12:50:28 EDT LOG:  could not receive data from client: No connection could be made because the target machine actively refused it.

2013-09-16 13:33:20 EDT ERROR:  CREATE DATABASE cannot be executed from a function or multi-command string
2013-09-16 13:33:20 EDT STATEMENT:  CREATE DATABASE firedata;
CREATE TABLE Plot_description(
plot_id smallint,
site_id smallint,
treatment varchar(8),
desc_sample_date date,
post1_over_sample_date date,
post2_over_sample_date date,
post3_over_sampe_date date,
elevation smallint,
slope smallint,
aspect smallint,
landform_code smallint,
position_code smallint,
shape_code smallint,
utm_zone smallint,
utm_n integer,
utm_e integer,
photo_dist real,
photo_azimuth smallint,
PRIMARY KEY (plot_id)
);
2013-09-16 13:41:07 EDT ERROR:  table "plot_description" does not exist
2013-09-16 13:41:07 EDT STATEMENT:  DROP TABLE Plot_description;
2013-09-16 13:45:57 EDT ERROR:  column "desc_sample_date" is of type date but expression is of type integer at character 60
2013-09-16 13:45:57 EDT HINT:  You will need to rewrite or cast the expression.
2013-09-16 13:45:57 EDT STATEMENT:  INSERT INTO plot_description VALUES ('2010-041',1,'Burned',7/20/2010,1663,15,142,3,1,3,18,3898624,747319,16.7,150);
2013-09-16 13:47:07 EDT ERROR:  column "post1_over_sample_date" is of type date but expression is of type integer at character 72
2013-09-16 13:47:07 EDT HINT:  You will need to rewrite or cast the expression.
2013-09-16 13:47:07 EDT STATEMENT:  INSERT INTO plot_description VALUES ('2010-041',1,'Burned','7/20/2010',1663,15,142,3,1,3,18,3898624,747319,16.7,150);
2013-09-16 13:54:15 EDT ERROR:  column "desc_sample_date" is of type date but expression is of type integer at character 60
2013-09-16 13:54:15 EDT HINT:  You will need to rewrite or cast the expression.
2013-09-16 13:54:15 EDT STATEMENT:  INSERT INTO plot_description VALUES ('2010-041',1,'Burned',7/20/2010,6/13/2012,'NULL','NULL',1663,15,142,3,1,3,18,3898624,747319,16.7,150);
2013-09-16 13:54:42 EDT ERROR:  invalid input syntax for type date: "NULL" at character 84
2013-09-16 13:54:42 EDT STATEMENT:  INSERT INTO plot_description VALUES ('2010-041',1,'Burned','7/20/2010','6/13/2012','NULL','NULL',1663,15,142,3,1,3,18,3898624,747319,16.7,150);
2013-09-16 14:32:19 EDT ERROR:  column "treament" does not exist at character 42
2013-09-16 14:32:19 EDT STATEMENT:  SELECT slope FROM plot_description WHERE treament = 'Control';
2013-09-16 14:38:52 EDT ERROR:  value too long for type character varying(12)
2013-09-16 14:38:52 EDT STATEMENT:  INSERT INTO landform VALUES 
(1, 'ridgetop'),
(2, 'open slope'),
(3, 'spur ridge'),
(4, 'gap'),
(5, 'knob'),
(6, 'plunging cove'),
(7, 'bottom'),
(8, 'bench');
2013-09-16 14:40:10 EDT ERROR:  type "charvar" does not exist at character 63
2013-09-16 14:40:10 EDT STATEMENT:  CREATE TABLE landform (
landform_code smallint,
landform_type charvar(14)
);
2013-09-16 14:49:49 EDT ERROR:  syntax error at or near "1" at character 23
2013-09-16 14:49:49 EDT STATEMENT:  INSERT INTO position
(1, 'upper'),
(2, 'mid'),
(3, 'lower');
2013-09-16 15:54:19 EDT ERROR:  syntax error at or near "Sugar" at character 72
2013-09-16 15:54:19 EDT STATEMENT:  INSERT INTO species VALUES
(1, 'Striped Maple'),
(2, 'Red Maple),
(3, 'Sugar Maple),
(4, 'Buckeye),
(5, 'Serviceberry),
(6, 'Yellow Birch),
(7, 'Sweet Birch),
(8, 'Muscle Wood),
(9, 'Hickory),
(10, 'American Chestnut),
(11, 'Hazelnut),
(12, 'Flowering Dogwood),
(13, 'Hawthorn),
(14, 'Persimmon),
(15, 'American Beech),
(16, 'White Ash),
(17, 'Ash),
(18, 'Silverbell),
(19, 'Witch Hazel),
(20, 'Mountain Holly),
(21, 'American Holly),
(22, 'Yellow Poplar),
(23, 'Cucumber Tree),
(24, 'Fraser Magnolia),
(25, 'Blackgum),
(26, 'Hophornbeam),
(27, 'Sourwood),
(28, 'Short Leaf Pine),
(29, 'Table Mt Pine),
(30, 'Loblolly Pine),
(31, 'Pitch Pine),
(32, 'White Pine),
(33, 'Virginia Pine),
(34, 'Sycamore),
(35, 'Fire Cherry),
(36, 'Black Cherry),
(37, 'White Oak),
(38, 'Scarlet Oak),
(39, 'Southern Red Oak),
(40, 'Blackjack Oak),
(41, 'Chestnut Oak),
(42, 'Northern Red Oak),
(43, 'Post Oak),
(44, 'Black Oak),
(45, 'Black Locust),
(46, 'Sassafras),
(47, 'Slippery Elm),
(48, 'Snag),
(49, 'Basswood),
(50, 'Eastern Hemlock),
(51, 'Carolina Hemlock);
2013-09-16 15:55:12 EDT ERROR:  syntax error at or near "Buckeye" at character 72
2013-09-16 15:55:12 EDT STATEMENT:  INSERT INTO species VALUES
(1, 'Striped Maple'),
(2, 'Red Maple),
(4, 'Buckeye),
(5, 'Serviceberry),
(6, 'Yellow Birch),
(7, 'Sweet Birch),
(8, 'Muscle Wood),
(9, 'Hickory),
(10, 'American Chestnut),
(11, 'Hazelnut),
(12, 'Flowering Dogwood),
(13, 'Hawthorn),
(14, 'Persimmon),
(15, 'American Beech),
(16, 'White Ash),
(17, 'Ash),
(18, 'Silverbell),
(19, 'Witch Hazel),
(20, 'Mountain Holly),
(21, 'American Holly),
(22, 'Yellow Poplar),
(23, 'Cucumber Tree),
(24, 'Fraser Magnolia),
(25, 'Blackgum),
(26, 'Hophornbeam),
(27, 'Sourwood),
(28, 'Short Leaf Pine),
(29, 'Table Mt Pine),
(30, 'Loblolly Pine),
(31, 'Pitch Pine),
(32, 'White Pine),
(33, 'Virginia Pine),
(34, 'Sycamore),
(35, 'Fire Cherry),
(36, 'Black Cherry),
(37, 'White Oak),
(38, 'Scarlet Oak),
(39, 'Southern Red Oak),
(40, 'Blackjack Oak),
(41, 'Chestnut Oak),
(42, 'Northern Red Oak),
(43, 'Post Oak),
(44, 'Black Oak),
(45, 'Black Locust),
(46, 'Sassafras),
(47, 'Slippery Elm),
(48, 'Snag),
(49, 'Basswood),
(50, 'Eastern Hemlock),
(51, 'Carolina Hemlock);
2013-09-16 15:55:43 EDT ERROR:  unterminated quoted string at or near "'Red Maple);" at character 54
2013-09-16 15:55:43 EDT STATEMENT:  INSERT INTO species VALUES
(1, 'Striped Maple'),
(2, 'Red Maple);
2013-09-16 17:07:12 EDT LOG:  received fast shutdown request
2013-09-16 17:07:12 EDT LOG:  aborting any active transactions
2013-09-16 17:07:12 EDT LOG:  autovacuum launcher shutting down
2013-09-16 17:07:12 EDT LOG:  shutting down
2013-09-16 17:07:12 EDT LOG:  database system is shut down

Re: How do I save my tables?

From
David Johnston
Date:
An errors-only log is useless for this kind of analysis.  its the successful
statements that truly matter (in combination with the errors).  You should
log all statements during our next session so a complete log is available
for review.  You should also annotate said log with your thoughts/comments
before posting it (and trim out the errors that you subsequently corrected).

You do not "save" tables.  If you issue a successful CREATE TABLE statement
that table will be permanent.

You need replicate what you did "yesterday" and document what you did in
much more detail if you want someone to try and figure out what went wrong.
So go in, create one table.  Insert and query it.  Close out pgAdmin and
reboot if you like.  Then go back in and see if the table is still there.
If not note any changes to the pgAdmin dialogs hat your made while adding
said table.  My on.y thought is that you created temporary tables (which go
away at session end).

David J.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-do-I-save-my-tables-tp5771217p5771228.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


Re: How do I save my tables?

From
Thomas Kellerer
Date:
David Johnston, 17.09.2013 14:59:
> You do not "save" tables.  If you issue a successful CREATE TABLE statement
> that table will be permanent.

Unless you disabled auto-commit and forgot to commit the CREATE TABLE statement...




Re: How do I save my tables?

From
Thomas Kellerer
Date:
Kimberly Israel, 17.09.2013 14:33:
> Yesterday I created several tables and was able to run queries that
> combined data from more than one table at a time, but when I reopened
> pgAdmin III today, the database I had created was there, but the
> tables were all gone.  I tried to save my work, but what got saved
> was a .sql file that seems to only contain the code for creating the
> database.  Basically what I need to know is how do I put my tables
> somewhere where I'll be able to continue working with them after a
> period of having the computer off?

This all sounds like you forgot to commit your changes.

When you have auto-commit disabled you need to commit every change you make to the database - including a CREATE TABLE
statement.



Re: How do I save my tables?

From
David Johnston
Date:
Thomas Kellerer wrote
> Kimberly Israel, 17.09.2013 14:33:
>> Yesterday I created several tables and was able to run queries that
>> combined data from more than one table at a time, but when I reopened
>> pgAdmin III today, the database I had created was there, but the
>> tables were all gone.  I tried to save my work, but what got saved
>> was a .sql file that seems to only contain the code for creating the
>> database.  Basically what I need to know is how do I put my tables
>> somewhere where I'll be able to continue working with them after a
>> period of having the computer off?
>
> This all sounds like you forgot to commit your changes.
>
> When you have auto-commit disabled you need to commit every change you
> make to the database - including a CREATE TABLE statement.

All true; and while I didn't actively ponder this scenario I find it
unlikely given the log file.  Given all of the syntax errors that we saw I
would have expected to see a large number of  (paraphrased) "current
transaction is aborted; ignoring all statements until Rollback has been
issued" messages.

Unless the OP was re-creating the table every time a typo occurred those
tables had to have been committed at some point during the session.

Also, I do not think the OP likely turned off auto-commit and so if that is
the default mode I would presume that said default is still in effect.

The temporary table thought is pretty much just as improbable but nothing
else readily comes to mind.

David J.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-do-I-save-my-tables-tp5771217p5771257.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


Re: How do I save my tables?

From
Kimberly Israel
Date:
Thanks for your advice everyone - I'm  getting ready to try it again and keep detailed track of the steps, but I noticed under Options->Query tool->Query editor that "Enable Auto ROLLBACK" is checked by default.  Is this the opposite of auto-commit?  Would unchecking it then put me into auto-commit?


From: David Johnston <polobo@yahoo.com>
To: pgsql-novice@postgresql.org
Sent: Tuesday, September 17, 2013 10:22 AM
Subject: Re: [NOVICE] How do I save my tables?

Thomas Kellerer wrote
> Kimberly Israel, 17.09.2013 14:33:
>> Yesterday I created several tables and was able to run queries that
>> combined data from more than one table at a time, but when I reopened
>> pgAdmin III today, the database I had created was there, but the
>> tables were all gone.  I tried to save my work, but what got saved
>> was a .sql file that seems to only contain the code for creating the
>> database.  Basically what I need to know is how do I put my tables
>> somewhere where I'll be able to continue working with them after a
>> period of having the computer off?
>
> This all sounds like you forgot to commit your changes.
>
> When you have auto-commit disabled you need to commit every change you
> make to the database - including a CREATE TABLE statement.

All true; and while I didn't actively ponder this scenario I find it
unlikely given the log file.  Given all of the syntax errors that we saw I
would have expected to see a large number of  (paraphrased) "current
transaction is aborted; ignoring all statements until Rollback has been
issued" messages.

Unless the OP was re-creating the table every time a typo occurred those
tables had to have been committed at some point during the session.

Also, I do not think the OP likely turned off auto-commit and so if that is
the default mode I would presume that said default is still in effect.

The temporary table thought is pretty much just as improbable but nothing
else readily comes to mind.

David J.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-do-I-save-my-tables-tp5771217p5771257.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


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


Re: How do I save my tables?

From
David Johnston
Date:
Kimberly Israel wrote
> Thanks for your advice everyone - I'm  getting ready to try it again and
> keep detailed track of the steps, but I noticed under Options->Query
> tool->Query editor that "Enable Auto ROLLBACK" is checked by default.  Is
> this the opposite of auto-commit?  Would unchecking it then put me into
> auto-commit?

Please follow list-norms (and others behavior) and bottom-post.

"Enable Auto ROLLBACK" only makes sense if you are in transaction (not
auto-commit) mode.  It makes it so that "transaction is aborted...." message
does not appear since as soon as you have an error the software issues a
ROLLBACK for you.

Still, unless you are constantly re-creating the tables in question whenever
you cause an error those tables should have been committed at some point.

I also do not know if that option is independent of the option to use
auto-commit...

David J.



--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-do-I-save-my-tables-tp5771217p5771267.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


Re: How do I save my tables?

From
Kimberly Israel
Date:
>An errors-only log is useless for this kind of analysis.  its the successful
>statements that truly matter (in combination with the errors).  You should
>log all statements during our next session so a complete log is available
>for review.  You should also annotate said log with your thoughts/comments
>before posting it (and trim out the errors that you subsequently corrected).

>You do not "save" tables.  If you issue a successful CREATE TABLE statement
>that table will be permanent.

>You need replicate what you did "yesterday" and document what you did in
>much more detail if you want someone to try and figure out what went wrong.
>So go in, create one table.  Insert and query it.  Close out pgAdmin and
>reboot if you like.  Then go back in and see if the table is still there.
>If not note any changes to the pgAdmin dialogs hat your made while adding
>said table.  My on.y thought is that you created temporary tables (which go
>away at session end).

>David J.

Is this what you mean by bottom-posting? With the arrows marking out the previous post?  I tried again and here's what happened:

Opened pgAdmin III, double clicked on PostgreSQL 9.3 (x86) (localhost: 5432)
Double clicked on database postgres, opened SQL query window

CREATE DATABASE firedata; 
-> Query returned successfully with no result in 3119 ms.
--Didn't see anything, went to Options and unchecked "Enable auto rollback", refreshed object browser and database was there.

CREATE TABLE landform (
landform_code smallint,
landform_type varchar(15)
);
-> Query returned successfully with no result in 31 ms.
--Didn't see any sign of the table in the object browser, even after refreshing.

INSERT INTO landform VALUES
(1, 'ridgetop'),
(2, 'open slope'),
(3, 'spur ridge'),
(4, 'gap'),
(5, 'knob'),
(6, 'plunging cove'),
(7, 'bottom'),
(8, 'bench');
->Query returned successfully: 8 rows affected, 11 ms execution time.
--Still no sense of where the table actually is

SELECT * FROM landform;
-> returns the table with the values I'd entered

Clicked "save file" from the toolbar and saved as landformtest.
Exited from pgAdmin III.

Reopened pgAmin III, double clicked on firedata database.

SELECT * FROM landform;
->ERROR:  relation "landform" does not exist
LINE 1: SELECT * FROM landform;
                      ^

Double clicked on postgres database in case the table somehow wound up there and tried to select from the table again, with the same result.

Re: How do I save my tables?

From
David Johnston
Date:
Kimberly Israel wrote
>>An errors-only log is useless for this kind of analysis.  its the
successful
>
>>statements that truly matter (in combination with the errors).  You should
>>log all statements during our next session so a complete log is available
>>for review.  You should also annotate said log with your thoughts/comments
>>before posting it (and trim out the errors that you subsequently
corrected).
>
>>You do not "save" tables.  If you issue a successful CREATE TABLE
statement
>>that table will be permanent.
>
>>You need replicate what you did "yesterday" and document what you did in
>>much more detail if you want someone to try and figure out what went
wrong.
>>So go in, create one table.  Insert and query it.  Close out pgAdmin and
>>reboot if you like.  Then go back in and see if the table is still there.
>>If not note any changes to the pgAdmin dialogs hat your made while adding
>>said table.  My on.y thought is that you created temporary tables (which
go
>>away at session end).
>
>>David J.
>
> Is this what you mean by bottom-posting? With the arrows marking out the
> previous post?  I tried again and here's what happened:
>
> Opened pgAdmin III, double clicked on PostgreSQL 9.3 (x86) (localhost:
> 5432)
> Double clicked on database postgres, opened SQL query window
>
> CREATE DATABASE firedata; 
> -> Query returned successfully with no result in 3119 ms.
> --Didn't see anything, went to Options and unchecked "Enable auto
> rollback", refreshed object browser and database was there.

transactions are turned on; "CREATE DATABASE firedata" created the database
but you cannot see it in the browser until you "commit".  Unchecking
"enable..." seems to have caused a commit for the CREATE DATABASE command
since you were able to connect to "firedata" down further.


> CREATE TABLE landform (
> landform_code smallint,
> landform_type varchar(15)
> );
> -> Query returned successfully with no result in 31 ms.
> --Didn't see any sign of the table in the object browser, even after
> refreshing.

Created the table "landform" in the "postgres" database - NOT firedata!!!!
Since the object browser uses a different session to query the catalogs the
table will not appear until you commit the "CREATE TABLE" transaction in
your interactive session.


> INSERT INTO landform VALUES
> (1, 'ridgetop'),
> (2, 'open slope'),
> (3, 'spur ridge'),
> (4, 'gap'),
> (5, 'knob'),
> (6, 'plunging cove'),
> (7, 'bottom'),
> (8, 'bench');
> ->Query returned successfully: 8 rows affected, 11 ms execution time.
> --Still no sense of where the table actually is
>
> SELECT * FROM landform;
> -> returns the table with the values I'd entered

The above is still done in "postgres"; you can see all prior work that you
performed in the same transaction so you can see the table here even though
it is not yet been committed to permanent storage.


> Clicked "save file" from the toolbar and saved as landformtest.

All you are saving here is the working query (the raw text content) in the
pgAdmin interface; this has nothing to do with telling the server to save
your transactional work.


> Reopened pgAmin III, double clicked on firedata database.
>
> SELECT * FROM landform;
> ->ERROR:  relation "landform" does not exist
> LINE 1: SELECT * FROM landform;
>                       ^

In the "firedata" database now, not "postgres", so the table you created in
"postgres" would not appear here even if you had committed.


> Double clicked on postgres database in case the table somehow wound up
> there and tried to select from the table again, with the same result.

Did not "commit" the CREATE TABLE transaction so the table you created and
inserted into in "postgres" was not committed to permanent storage.

David J.






--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-do-I-save-my-tables-tp5771217p5771279.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


Re: How do I save my tables?

From
Kimberly Israel
Date:
>SELECT * FROM landform;
>->ERROR:  relation "landform" does not exist
>LINE 1: SELECT * FROM landform;
                      ^
I got a private response and wanted to let people know the problem has been solved.

I had apparently not moved into the firedata database after creating it, so my tables were stuck on the postgres database.  When I double clicked on firedata and then created my table, it was still there after I restarted.

Thanks for your help, everyone!