Basic Usage: 4.1. Starting and Stopping The Server
Basic Usage: 4.1. Starting and Stopping The Server
html
4. Basic Usage
The intention behind this section is to allow you to get started with the Sybase-specific parts quickly. You will still need to know a little bit about relational
databases, creating tables, designing the database and so on. You will see how to start and stop the server, execute commands and a little bit about backups.
1>
If the connection did not succeed, make sure the server is running and that the port is reported by netstat -na to have a LISTENING state.
You can now start typing T-SQL commands and use the keyword "go" as a terminator.
(1 row affected)
Now sa has a new password, changed from the old null default. We add a new login with sp_addlogin:
We can log out by telling isql to disconnect using the exit command.
1> exit
Since this is not a T-SQL command but a directive to isql we don't need to terminate with "go".
The isql command can also be used non-interactively to apply scripts of T-SQL to the server. One such script that is shipped with the server is installpubs2,
located in the scripts directory. This is a very simple example database for a bookshop or a publishing house holding data about books, authors, publishers and so
on. It is used in Sybase manuals and training courses and also in some SQL books. Microsoft SQL Server contains a similar database in addition to the
Northwind example database they have added. In order to create the database, use the -i parameter to read the script in. Have a look at the file first so you
understand the basics of what it is doing; it will create a database named pubs2 and several tables populated with data. It is time to execute the script. We'll do
this as sa who will also become the owner (dbo - database owner ) of the database. We redirect the output to a file we call errors.out. The -e parameter tells isql
to also echo the T-SQL commands to the same file, giving more output but making it easier to match any errors to the commands causing them.
1 of 3 31-05-2024, 15:54
Basic Usage https://tldp.org/HOWTO/Sybase-ASE-HOWTO/usage.html
bash$ cd $SYBASE/$SYBASE_ASE/scripts
bash$ isql -Usa -PSecr3t -SSYBASE -iinstallpubs2 -e -oerrors.out
In order to allow our new login full privileges to this sample database we change ownership of the database to the new login. Here's how we give the database
away with sp_changedbowner:
We can now log in interactively as our new user and check what has been installed.
1> exit
bash$ isql -Usybtest -PSomePass -SSYBASE
1> use pubs2
2> go
1> sp_help
2> go
[Lots of output deleted - the command displays all objects in the current database]
(Note that we don't actually have to use "exec" to execute a stored procedure, the server will assume any non-keyword is a procedure.)
1> quit
One last command as the sa login in order to make life more convenient when we continue to use our new login - we make the new pubs2 database the default
database.
1> exit
bash$ isql -Usa -PSecr3t -SSYBASE
1> sp_modifylogin sybtest, "defdb", "pubs2"
2> go
Default database changed.
(return status = 0)
You will immediately be disconnected and a message is printed by isql to warn you of this fact. You can check the error log for a message about the server being
shutdown and you can verify that the process is no longer running with showserver.
4.5. Maintenance
One of the most important aspects of being a database administrator may be the backup. The I/O load of a relational database means little rest for the hard drives
and once a drive fails the database is in need of serious disaster recovery. Even a mistyped command may result in the need to revert to a previous backup
generation. For this purpose, a separate server application called the Backup Server is used. It is by default named the same as your server with an extension of
BCK. Start it with startserver -f RUN_SYBASE_BCK. Certain commands typed into the isql propmt will be forwarded from the dataserver process to the
backupserver process, which will then proceed with the actual backup (in Sybase terminology, this is a database dump) while processing in the database
continues unaffected. You should schedule database dumps (usually via cron) to run at low activity hours. A typical full database bacup is simply done like this:
You can restore this back into your database using the load database command.
As time passes while users are doing modifications in the database, adding, deleting or changing data, all operations are being written to the transaction log. This
keeps track of changes so they can be undone by an implicit or explicit rollback, or for the undo/redo phases of revocery at startup. This transaction log should
normally be placed on a device of its own for several reasons, but a small test database can be created on a single mixed log and data device.
Apart from the performance benefits of spreading I/O, one reason for keeping the log and data separate is for recovery purposes. You can at regular intervals,
depending upon your recovery needs, dump this log of changes to the database. Together with the full database dump, this transaction log dump now constitute
2 of 3 31-05-2024, 15:54
Basic Usage https://tldp.org/HOWTO/Sybase-ASE-HOWTO/usage.html
an incremental backup. Should a restore become necessary, you can load the database dump, then load all subsequent transaction log dumps. There is even an
"until_time" option to the load command enabling you to specify the exact time you want to restore until, abandoning any mistakes done after that time.
Dumping the log is done with a similar syntax:
Note that we could not do this with pubs2 as it was not created with a separate log fragment.
Unless you keep dumping the transaction log, it will just keep growing until it fills up it's space and starts reporting error 1105. Users will be suspended and
appear to be hanging while the situation remains unresolved. Dump the transaction log to file or tape, or simply truncate it if you don't use incremental backups.
DBCC, the DataBase Consistency Checker which will verify that the physical integrity of the data structures on the ASE devices are OK.
update statistics, which will make sure that ASE has a correct view of how your data is distributed in your tables, enabling it to make the best decisions of
how to retrieve the data in the shortest possible time.
bcp or Bulk Copy is a command-line utility with a plethora of parameters that imports table data from flat files and exports data out to files.
Sybase Central is a GUI tool for database adminstration. It used to be a native Win32 application, but in ASE 12.5.0.x it is now Java based and can be
installed on Linux. Note that you also need to install and register the plug-in for administering ASE since Sybase Central is only a framework which is
used for many Sybase products by registering their respective plugins.
Jisql is a Java based GUI version of isql with some neat features such as command history and table and column name lookup.
3 of 3 31-05-2024, 15:54