dbTalk Databases Forums  

Moving from MySQL to PGSQL....some questions

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss Moving from MySQL to PGSQL....some questions in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Karam Chand
 
Posts: n/a

Default Moving from MySQL to PGSQL....some questions - 02-25-2004 , 08:57 AM






Hello

I have been working with Access and MySQL for pretty
long time. Very simple and able to perform their jobs.
I dont need to start a flame anymore

I have to work with PGSQL for my companies current
project.

I have been able to setup postgresql in my rh box and
i can connect and work with psql. I even downloaded
pgadmin III so that i can get to work with a GUI
interface.

As I starting...I see the architecture of PGSQL is
quite complex...or thats what I feel....maybe its for
good Here are some of my doubts :

1.) What is template1 and template0? I assume these
are system databases. Am I right?

2.) When I create a database using CREATE DATABASE
stmt. a new DB is created where it has 4 schemas and
around 100 tables. These are the system tables keeping
information about everything in the database? I hope I
am correct

3.) To get all the database is the server we use query
like -

select datname from pg_database

I means that there exists a table pg_database in all
the database and all the pg_database table(s) are
updated whenever a user issues CREATE DATABASE stmt.

Why I am saying so coz in PgAdmin III i can see these
tables in all the databases?

4.) I couldnot find any query to change the context of
database like in MySQL :

use database;

or am i missing something?

5.) In MySQL, there are many command like show tables,
show databases etc. to get object details. I cant see
anything similar in PGSQL. After searching the net i
find that i have to execute certain queries to fetch
those queries. Is this the only way?

Any help would be appreciated.

Regards
Karam



__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
  #2  
Old   
Dave Cramer
 
Posts: n/a

Default Re: Moving from MySQL to PGSQL....some questions - 02-25-2004 , 09:11 AM






Karam,

try \? to get answers to your questions.

Dave
On Wed, 2004-02-25 at 09:57, Karam Chand wrote:
Quote:
Hello

I have been working with Access and MySQL for pretty
long time. Very simple and able to perform their jobs.
I dont need to start a flame anymore

I have to work with PGSQL for my companies current
project.

I have been able to setup postgresql in my rh box and
i can connect and work with psql. I even downloaded
pgadmin III so that i can get to work with a GUI
interface.

As I starting...I see the architecture of PGSQL is
quite complex...or thats what I feel....maybe its for
good Here are some of my doubts :

1.) What is template1 and template0? I assume these
are system databases. Am I right?

2.) When I create a database using CREATE DATABASE
stmt. a new DB is created where it has 4 schemas and
around 100 tables. These are the system tables keeping
information about everything in the database? I hope I
am correct

3.) To get all the database is the server we use query
like -

select datname from pg_database

I means that there exists a table pg_database in all
the database and all the pg_database table(s) are
updated whenever a user issues CREATE DATABASE stmt.

Why I am saying so coz in PgAdmin III i can see these
tables in all the databases?

4.) I couldnot find any query to change the context of
database like in MySQL :

use database;

or am i missing something?

5.) In MySQL, there are many command like show tables,
show databases etc. to get object details. I cant see
anything similar in PGSQL. After searching the net i
find that i have to execute certain queries to fetch
those queries. Is this the only way?

Any help would be appreciated.

Regards
Karam



__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

--
Dave Cramer
519 939 0336
ICQ # 14675561


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly



Reply With Quote
  #3  
Old   
Shridhar Daithankar
 
Posts: n/a

Default Re: Moving from MySQL to PGSQL....some questions - 02-25-2004 , 09:14 AM



Karam Chand wrote:
Quote:
1.) What is template1 and template0? I assume these
are system databases. Am I right?
Yes. whenever a new database is created, these databases are copied there. So
these are like initial master copies.

Quote:
2.) When I create a database using CREATE DATABASE
stmt. a new DB is created where it has 4 schemas and
around 100 tables. These are the system tables keeping
information about everything in the database? I hope I
am correct
Yes.

Quote:
3.) To get all the database is the server we use query
like -

select datname from pg_database

I means that there exists a table pg_database in all
the database and all the pg_database table(s) are
updated whenever a user issues CREATE DATABASE stmt.

Why I am saying so coz in PgAdmin III i can see these
tables in all the databases?
Some tables such as users/passwords/groups and databases are shared across all
the databases. You are looking at same data.
Quote:
4.) I couldnot find any query to change the context of
database like in MySQL :

use database;

or am i missing something?
Any postgresql session has to connect to a database. To connect to different
database, you need to initiate a new connection or drop existing one and create
new one.

You can not switch the database-connected-to on the fly.

Quote:
5.) In MySQL, there are many command like show tables,
show databases etc. to get object details. I cant see
anything similar in PGSQL. After searching the net i
find that i have to execute certain queries to fetch
those queries. Is this the only way?
No. Simplest would be issuing \? on psql prompt. It will tell you plethora of
options/commands using which you can accomplish many task. Just remember that
these are not SQL command provided by server. It is the psql application which
provide these commands. So you cannot use them in say php.

Quote:
Any help would be appreciated.
HTH

Shridhar

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
  #4  
Old   
Dennis Bjorklund
 
Posts: n/a

Default Re: Moving from MySQL to PGSQL....some questions - 02-25-2004 , 09:25 AM



On Wed, 25 Feb 2004, Karam Chand wrote:

Quote:
1.) What is template1 and template0? I assume these
are system databases. Am I right?
When you create a new database what you get is a copy of template1.

template0 is alsmost not used. If you mess up template1 so you can't
create usable new databases one can use template0 to create a new
template1.

The system tables are a bit complexed and some are shared between all
databases.

Quote:
3.) To get all the database is the server we use query
like -

select datname from pg_database
or \l in psql

Quote:
I means that there exists a table pg_database in all
the database and all the pg_database table(s) are
updated whenever a user issues CREATE DATABASE stmt.
yes, pg_database is a shared table.

Quote:
4.) I couldnot find any query to change the context of
database like in MySQL :

use database;
\c in psql.
Quote:
5.) In MySQL, there are many command like show tables,
show databases etc. to get object details. I cant see
anything similar in PGSQL. After searching the net i
find that i have to execute certain queries to fetch
those queries. Is this the only way?
\d and others.

\? is a useful command. Also the man page (man psql) can help.

--
/Dennis Björklund


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



Reply With Quote
  #5  
Old   
Karam Chand
 
Posts: n/a

Default Re: Moving from MySQL to PGSQL....some questions - 02-25-2004 , 09:45 AM



Thanks. That was very helpful

One more thing (it might be slightly off topic):

I have two computers on network, one is running RH
Linux and one running WInXP. My PostgreSQL is running
in Linux box.

I downloaded PgAdmin III for both OS. When I am
connecting from the Linux box I am able to view the
three system schemas :

pg_catalog
pg_temp_1
pg_toast

When I am accessing it using PgAdmin III on Windows I
can only see the 'public' schema and its tables? Why
is it so?

Regards
Karam

-- Shridhar Daithankar <shridhar (AT) frodo (DOT) hserus.net>
wrote:
Quote:
Karam Chand wrote:
1.) What is template1 and template0? I assume
these
are system databases. Am I right?

Yes. whenever a new database is created, these
databases are copied there. So
these are like initial master copies.

2.) When I create a database using CREATE DATABASE
stmt. a new DB is created where it has 4 schemas
and
around 100 tables. These are the system tables
keeping
information about everything in the database? I
hope I
am correct

Yes.

3.) To get all the database is the server we use
query
like -

select datname from pg_database

I means that there exists a table pg_database in
all
the database and all the pg_database table(s) are
updated whenever a user issues CREATE DATABASE
stmt.

Why I am saying so coz in PgAdmin III i can see
these
tables in all the databases?

Some tables such as users/passwords/groups and
databases are shared across all
the databases. You are looking at same data.

4.) I couldnot find any query to change the
context of
database like in MySQL :

use database;

or am i missing something?

Any postgresql session has to connect to a database.
To connect to different
database, you need to initiate a new connection or
drop existing one and create
new one.

You can not switch the database-connected-to on the
fly.

5.) In MySQL, there are many command like show
tables,
show databases etc. to get object details. I cant
see
anything similar in PGSQL. After searching the net
i
find that i have to execute certain queries to
fetch
those queries. Is this the only way?

No. Simplest would be issuing \? on psql prompt. It
will tell you plethora of
options/commands using which you can accomplish many
task. Just remember that
these are not SQL command provided by server. It is
the psql application which
provide these commands. So you cannot use them in
say php.

Any help would be appreciated.

HTH

Shridhar

__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
  #6  
Old   
Jean-Michel POURE
 
Posts: n/a

Default Re: Moving from MySQL to PGSQL....some questions - 02-25-2004 , 10:33 AM



Le Mercredi 25 Février 2004 16:45, Karam Chand a écrit :
Quote:
When I am accessing it using PgAdmin III on Windows I
can only see the 'public' schema and its tables? Why
is it so?
Have a deeper look at pgAdmin III menu:
Display>-System objects

pgAdmin III includes the documentation of PostgreSQL.
It is highly recommended to dig into the documentation.

By the way, if one of you was interested by translating pgAdmin into any
language not yet supported, you are welcome.

Cheers,
Jean-Michel


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
  #7  
Old   
Bill Moran
 
Posts: n/a

Default Re: Moving from MySQL to PGSQL....some questions - 02-25-2004 , 10:38 AM



Dennis Bjorklund wrote:
Quote:
On Wed, 25 Feb 2004, Karam Chand wrote:

1.) What is template1 and template0? I assume these
are system databases. Am I right?

When you create a new database what you get is a copy of template1.

template0 is alsmost not used. If you mess up template1 so you can't
create usable new databases one can use template0 to create a new
template1.
More specifically (as I understand it) template1 is intended to be a
template (with default settings and the like) for creating new databases.
So (for example) if your business policy is that all created databases
use plpgsql, you can createlang it into template1, and every database
created thereafter will already have plpgsql. If you have specific
tables or the like that every database on that server should have, you
can put them in template1 so they are always there.

template0 is what you use to fix things, if you mess up template1
somehow.

--
Bill Moran
Potential Technologies
http://www.potentialtech.com


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



Reply With Quote
  #8  
Old   
Michael Chaney
 
Posts: n/a

Default Re: Moving from MySQL to PGSQL....some questions - 02-25-2004 , 10:40 AM



On Wed, Feb 25, 2004 at 06:57:04AM -0800, Karam Chand wrote:
Quote:
4.) I couldnot find any query to change the context of
database like in MySQL :

use database;
Your other questions were answered more than adequately by others, but I
thought I'd provide more details here.

If you're in the command line psql, then use "\c database" to accomplish
this. The drawback is that you cannot change the database in that
manner programmatically. If you're using Perl or PHP, for instance, you
must connect to the other database explicitly using the proper function.
In Perl, this means you must use DBI->connect again with the new
database name.

In MySQL, you can get data from another database by using the construct
"datbase.table" to refer to the table. This doesn't work in Postgres.

If you need to do something like that, you likely need to be using
schemas.

I've put together a quick list of minor differences between MySQL and
Postgres (besides the obvious "real RDBMS" features that exist only in
Postgres) that should help you get started:

http://www.michaelchaney.com/mysql-to-postgres.html

That includes information on date handling, literal quoting, basically
anything that I ran in to while converting an application. But it
should help you get started quickly.

Michael
--
Michael Darrin Chaney
mdchaney (AT) michaelchaney (DOT) com
http://www.michaelchaney.com/

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
  #9  
Old   
Shachar Shemesh
 
Posts: n/a

Default Re: Moving from MySQL to PGSQL....some questions - 02-25-2004 , 11:17 AM



Shridhar Daithankar wrote:

Quote:
show databases etc. to get object details. I cant see
anything similar in PGSQL. After searching the net i
find that i have to execute certain queries to fetch
those queries. Is this the only way?

5.) In MySQL, there are many command like show tables,

No. Simplest would be issuing \? on psql prompt. It will tell you
plethora of options/commands using which you can accomplish many task.
Just remember that these are not SQL command provided by server. It is
the psql application which provide these commands. So you cannot use
them in say php.

If you run psql with the "-E" parameter, whenever you execute a psql
command that translates to a query, that query will be displayed on
screen. This allows you to check out what queries you need for certain
operations.

For example - to check all the tables in the current database/schema:
$ psql -E db
Welcome to psql 7.4.1, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

db=# \dt
********* QUERY **********
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i'
THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as "Type",
u.usename as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
**************************

List of relations
Schema | Name | Type | Owner
--------+--------------+-------+-------

Check out the rest of the \d* commands for more listings (\? will give
you the list).

Also, it pays to look up the meaning of the above in the documentation.
The system tables are documented in
http://www.postgresql.org/docs/7.4/static/catalogs.html

Quote:
Any help would be appreciated.

Shachar

--
Shachar Shemesh
Lingnu Open Systems Consulting
http://www.lingnu.com/


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



Reply With Quote
  #10  
Old   
Michael Chaney
 
Posts: n/a

Default Re: Moving from MySQL to PGSQL....some questions - 02-25-2004 , 06:09 PM



One other note, for those converting a database from MySQL to
PostgreSQL, I have a table creation conversion script here:

http://www.michaelchaney.com/downloads/m2p.pl

I know that two come with PostgreSQL in the contrib directory, but I
wrote this because those two didn't do what I needed. With this, you
should be able to take the MySQL table creation scripts (as created by
mysqldump --tab=x) and directly build the tables and load the data into
a PostgreSQL db with little effort.

Michael
--
Michael Darrin Chaney
mdchaney (AT) michaelchaney (DOT) com
http://www.michaelchaney.com/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.