Web Support -- Databases -- PostgreSQL
What is PostgreSQL?

PostgreSQL is an open-source object-relational database management system (DBMS) with strong support for the ANSI standard for the Structured Query Language (SQL).

What is DCANet's PostgreSQL service?

As part of its DCANet's web hosting suite of services, DCANet offers a SQL database service. Many DCANet web hosting customers choose a SQL-powered database to add features to a web site; for instance, a customer database for storing information about returning users might be powered by a SQL database.

DCANet offers three choices for SQL-based database hosting: PostgreSQL, MySQL and Microsoft SQL Server. This document addresses only PostgreSQL. The version of PostgreSQL used by DCANet is version 7.0.

DCANet's PostgreSQL service will allow web hosting customers to query and update a SQL database, create/delete/modify SQL tables, and perform other SQL commands via PHP 4 or via Perl. While other methods of querying a PostgreSQL database are possible (e.g. C, C++, TCL, and Python), DCANet provides support only for PHP 4 and Perl.

How do I obtain a PostgreSQL database for my web site?

To request a database or obtain pricing information, contact websupport@dca.net.

Once my database is set up, how do I use it?

DCANet will contact you once your database is ready to use. You will be given a database name, a username, and a password to access your database. This information, along with the host name of DCANet's PostgreSQL server, can be used to access your database from DCANet's web servers. DCANet's PostgreSQL server is pgsql.dca.net.

Please note that access to pgsql.dca.net is limited by IP address as well. That means that you cannot directly query your database from a remote location without specific prior arrangements. If you need remote query ability, please contact websupport@dca.net.

Example of Perl code for PostgreSQL access

DCANet recommends and supports the DBI tools for accessing PostgreSQL from Perl. More documentation on Perl DBI can be found in the CPAN DBI FAQ.

#!/usr/bin/perl

use DBI;
$db_server = "psql.dca.net";
$db_name = "mydb";
$db_username = "myusername";
$db_password = "mypassword";
$data_source = "dbi:Pg:dbname=$db_name;host=$db_server;port=5432";

my $dbh = DBI->connect($data_source,$db_user,$db_pass)
  || die "Cannot connect to database: $DBI::errstr\n";

$cmd = "select * from bar where something='somethingelse'";
my $sth = $dbh->do($cmd)
  || die ("Unable to execute $cmd: $DBI::errstr");

(...)

$dbh->disconnect || warn $dbh->errstr;

Example of PHP code for PostgreSQL access

DCANet supports PHP version 4 for PostgreSQL access. More information on PostgreSQL and PHP can be found on PHP4.NET.

<HTML>
<BODY>

Connecting to PostgreSQL database via PHP...

<?

// Variable declarations
   $db_server = "pgsql.dca.net";
   $db_name = "mydb";
   $db_username = "myusername";
   $db_password = "mypassword";

// Connect to database
   $dbh = pg_connect("host=$db_server dbname=$db_name user=$db_username password=$db_password");
   if ($dbh )
   {
      print "Connected okay!<p>";
   }
   else
   {
      print "Error connecting.<p>";
   }
   pg_close($dbh) if ($dbh);

?>

End of test.
</BODY>
</HTML>

Additional notes

Please note that your web site must have PHP enabled if you intend to use PHP scripts. Please be sure to request PHP support if you plan to use PHP.

DCANet may update this documentation from time to time or change its support for PostgreSQL access methods without advance warning.

DCANet administrative staff reserves the right to shut down your database, disable your web site, or perform other appropriate corrective action if your scripts cause harm to or significantly degrade the performance of DCANet's web servers and/or DCANet's PostgreSQL server. DCANet will make every effort to avoid doing so and to contact you ahead of time when possible.