Salı, Aralık 08, 2009

postgres plperl destegi

Ubuntuda postgresql-plperl-8.4 paketini yukle.

createlang plperl -U kullanici -d veritabani -W

shell komutuyle dili veritabanina yukle.


create function caps(text) returns text as $$
my $x=$_[0];
$x =~ tr/[a-z]/[A-Z/;
return $x;
$$ LANGUAGE plperl;

select caps('der der');
caps
----------
DER DERE
(1 row)

Pazartesi, Kasım 23, 2009

Veritabaninda metin depolama

Super bir hesap yontemi. Sol kulagi sag elle tutmus biraderler ama yine de okay. 2.5 MB veriyi 5.2 MB olarak saklayacak bir veritabani sistemi ne ise yarar benim icin. Hic bir ise yaramaz.

Neticede metin dosyalarini dosya sisteminde tutmak daha akillica anlasilan.
Peki CouchDB nasil hallediyor bu isi. BLOB olarak tuttuklarini biliyorum sadece. Bakalim.

Cuma, Kasım 20, 2009

Veri dizinini degistirmek icin

Bu yazi 8.2 icin.

Pazartesi, Ekim 05, 2009

Postgres degisken

\set degisken 'lalala'

Sadece \set mevcut degiskenleri listeler

select * from tablo where sutun=:degisken;

Tabloyu dosyaya aktar

Either:

SELECT * FROM table \g filename

to just output to the file 'filename', or:

select * from lineshoot \g |cat >> /solsolute/path/filename

to append to the file. Both in psql, or:

echo 'SELECT * FROM table' | psql database >> test.out

from your terminal

Perşembe, Temmuz 30, 2009

Oracle da dosyadan metin yukleme

Example 10-18 Loading LOB DATA with One LOB per LOBFILE

Control File Contents

LOAD DATA
INFILE 'sample.dat'
INTO TABLE person_table
FIELDS TERMINATED BY ','
(name CHAR(20),
1 ext_fname FILLER CHAR(40),
2 "RESUME" LOBFILE(ext_fname) TERMINATED BY EOF)

Datafile (sample.dat)

Johny Quest,jqresume.txt,
Speed Racer,'/private/sracer/srresume.txt',

Secondary Datafile (jqresume.txt)

Johny Quest
500 Oracle Parkway
...

Secondary Datafile (srresume.txt)

Speed Racer
400 Oracle Parkway
...


http://students.kiv.zcu.cz/doc/oracle/appdev.102/b14259/xdb25loa.htm

Burada da XML yukleme ile ilgili ornek var.

Salı, Temmuz 28, 2009

Postgresql XML alani

Create table test
(y int, data xml);

insert into test values (1, 'ffr');

select xpath ('/foo/text()', data) from test;
xpath
-------
{ffr}
(1 row)

Pazartesi, Temmuz 27, 2009

Metin arama destegi

Ornek bir sorgu:

select 'a fat cat'::tsvector @@ 'cat'::tsquery;

Diger sorgu sekilleri icin kaynaklar:
  1. http://www.postgresql.org/docs/8.3/static/functions-textsearch.html
  2. http://www.postgresql.org/docs/8.3/static/ddl-schemas.html

Perşembe, Haziran 25, 2009

MySQL cluster/ ubuntu

MySQL cluster'i Ubuntu'da derlmek icin en azindan asagidakiler gerekiyor:
sudo apt-get install gcc
sudo apt-get install libgcc1
sudo apt-get install g++
sudo apt-get install cpp
sudo apt-get install ncurses-base
sudo apt-get install ncurses-bin
sudo apt-get install ncurses-term
sudo apt-get install libncurses5

sudo apt-get install libncurses5-dev

Ekstra zlip, dokumantasyon icin doxygen

Salı, Haziran 23, 2009

mod-ndb icin mysql hesabi

create user 't'@'66.222.66.222' identified by 'm';
grant all privileges on *.* to 't'@'66.222.66.222' with grant option;

Çarşamba, Mayıs 20, 2009

Mac OS 10.5 icin MySQL cluster kurulumu

05/20/2009
Mac OS 10.5 Server a mySQL clusteri kurmaya calistim.
Config dosyalarinda localhost deyince calismadi IP adresi verdim.

once ndb_mgmd
cd /usr/local/mysql/bin
sudo ./ndb_mgmd -f /var/lib/mysql-cluster/config.ini
sonra ndbd
sudo ./ndbd

Not: /usr/bin/mysql eski kuruluma isaret ediyor.

Apache modulu yazmak icin neler gerekiyor?

Cok cok temel bir ornek. Muhakkak dene!

apxs -g -n foo ile basla!

Mac server ve mysql kaldir

Mevcut Mac de mysql /var/mysql e kurulmus. Ama onemi yok! Yeni kuracagim su sekilde olacak ve kaldirmak gerekirse aklimda bulunsun.

  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
  • sudo rm -rf /Library/Receipts/mysql*
  • sudo rm -rf /Library/Receipts/MySQL*
http://www.entropy.ch/software/macosx/mysql/

Yukaridaki de onemli bir kaynak.

Salı, Mayıs 19, 2009

Mac server ve mysql

Applications->Server->Server Admin
Server'in adini dokun ve cift tiklayinca sifreni gir.

MySQL sagdaki listede. Ilk once en altta stop mysql butonuna bas. Sonra Settings sekmesine gidip sagdaki Set MySQLRoot password ile sifreni degistir.

Salı, Mayıs 12, 2009

http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html

To use SET PASSWORD on Unix, do this:

anonymous account passwd or removal
shell> mysql -u root
mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');

shell> mysql -u root
mysql> DROP USER ''@'localhost';

shell> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');

Resetting permission
http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html

Postgres

''
Created on Apr 6, 2009
http://www.sqlalchemy.org/docs/05/dbengine.html#supported-dbapis
Sorce code from: http://www.ibm.com/developerworks/aix/library/au-sqlalchemy/
@author:
'''

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine

Base = declarative_base()

#Table class: path as primary key
class Filesystem(Base):
__tablename__ = 'filesystem'

path = Column(String, primary_key=True)
name = Column(String)

def __init__(self, path,name):
self.path = path
self.name = name

def __repr__(self):
return "" % (self.path,self.name)


#psycopg2 is needed for postgres connection, use synaptic pakage manager
#The actual table will not be created until you run code to create a table,
#and you also need to define what database engine SQLAlchemy will use
#
engine = create_engine('postgres://tulay:tulay@localhost:5432/testdb',echo=True)

Base.metadata.create_all(engine)
#Base.metadata.drop_all(engine)

#At this point, we know enough to create a SQLAlchemy project and control the database from the SQLAlchemy API.
#The only other major item to tackle before getting into a real-life example is the concept of a session.
#The SQLAlchemy "official" documentation describes the session as the handle to the database.
#In practical use, it allows for distinct, transaction-based, connections to occur from a pool of connections
#that SQLAlchemy has waiting. Inside of a session it is typical to add data to the database, perform queries, or delete data.
#
#In order to create a session, perform these sequential steps:

#establish Session type, only need to be done once for all sessions
Session = sessionmaker(bind=engine)
#create record object
create_record = Filesystem("/tmp/foo.txt", "foo.txt")
#make a unique session
session = Session()
#do atomic in session. We are inserting a record here
session.add(create_record)
#commit the transaction
session.commit()

#$pysql testdb

#select * from filesystem;

# path | name
# --------------+---------
# /tmp/foo.txt | foo.txt
#(1 row)

Pazartesi, Nisan 06, 2009

Postgres

1. Adım:

postgres kullanıcı hesabı aç Ubuntuda postgres'i yükleyince otomatik olarak kurulmuş. sudo su - postgres

2. Adım:
psql
create role kullaniciAdi login;

3. Adım:
psql
alter role kullaniciAdi with password 'gizli';
exit

createdb veritabani
createdb: database creation failed: ERROR: permission denied to create database

4. Adım:
psql
alter role kullaniciAdi createdb;

5. Adım:
(komut satırından)
createdb veritabani
ya da
createdb -U kullaniciAdi veritabani



6. Adım:
(komut satırından)
psql veritabani
\q (Sistemden çıkmak için)

7. Adım:
(Veritabanını düşürmek için)
dropdb veritabani


8. Adım:
createdb bookstore

9. Adım:
psql bookstore

10. Adım:
CREATE TABLE
bookstore=> create table books(
author varchar(15),
title varchar(50),
price int
);

Burada veritabanı yaratılıyor. Ancak public schemaya ait. Onceden
CREATE SCHEMA benimki AUTHORIZATION kullaniciAdi;
demek sonra

CREATE benimki.books( ...)
demek daha uygun.

Eger benimki kismini yani sema adini unutrsan otomatik olarak kullanici adi olarak yaratiliyor.

Bu vt altında tablolar vs yaratılacak.

show search_path;
create schema data authorization metavana;
set search_path to data;
show search_path;

Notlar:
Role=user=group


Eger asagidaki gibi bir hata aliyorsan:
psql: FATAL: IDENT authentication failed for user "gateadmin"

Su dosyayi degistir:
pg_hba.conf ( trust kismi degisicek)

local all trust
host all 127.0.0.1 255.255.255.255 trust

Kaynaklar:
1) debian.uk

Cumartesi, Şubat 21, 2009

Bazi db2 komutlari

  • db2stop: Stop database

  • db2start: Start database

  • db2text: start text services

  • db2jstrt: start java listener

  • db2level: Komut satirindan DB2 surumunu ogrenmek icin

  • DB2 Log Files

    • /home/db2inst1/sqllib/db2dump/db2diag.log: for all DB2 errors/warnings

    • "jdbcerr.log" for errors/warning relating to Java JDBC connections

  • db2 force application all : disconnect all users from database

  • db2 list applications for db dbname: Information for each application that is connected to the specified database is to be displayed.

  • The following example shows how to describe a table:

   db2 describe table user1.department
  • To reset a registry variable for an instance back to the default found in the Global Profile Registry, use:

   db2set -r registry_variable_name 
  • To delete a variable's value at a specified level, you can use the same command syntax to set the variable but specify nothing for the variable value. For example, to delete the variable's setting at the node level, enter:

   db2set registry_variable_name= -i instance_name      node_number