PHPでHello World

(20)

apt install php7.4-cli
php -v


vim hello.php

<?php
echo "Hello World!";
?>

php hello.php

--
vim web.php

<?php
echo "Hello World!!";
?>

php -S 192.168.137.167:8080 web.php

(10)

apt install php7.3-cli
php -v


vim hello.php

<?php
echo "Hello World!";
?>

php hello.php

--
vim web.php

<?php
echo "Hello World!!";
?>

php -S 192.168.137.156:8080 web.php

 

(8)

dnf install php-cli
php -v


vim hello.php

<?php
echo "Hello World!";
?>

php hello.php

--
vim web.php

<?php
echo "Hello World!!";
?>

php -S 192.168.137.165:8080 web.php

 

(2019)
https://windows.php.net/download#php-7.2
php-7.2.33-1-Win32-VC15-x64.zip

cd C:\Users\Administrator\Downloads\php-7.2.33-1-Win32-VC15-x64

php -v


notepad hello.php

<?php
echo "Hello World!";
?>

php hello.php

--
notepad web.php

<?php
echo "Hello World!!";
?>

php -S 192.168.137.61:8080 web.php

 

ロック行のスキップ

(8.0.21)


drop table tab1;
create table tab1(col1 int,col2 int,col3 varchar(10) );

create index ind11 on tab1(col1);

insert into tab1 values(1,100,'off');
insert into tab1 values(2,100,'off');
insert into tab1 values(3,100,'off');
select * from tab1;

-- session1
start transaction;
select * from tab1 where col2 = 100 and col3 = 'off' order by col1 limit 1 for update;

-- session2
start transaction;
select * from tab1 where col2 = 100 and col3 = 'off' order by col1 limit 1 for update;

→待ちになる

start transaction;
select * from tab1 where col2 = 100 and col3 = 'off' order by col1 limit 1 for update skip locked;

→col1 = 2 の行でロック取得できる

(12cR1)

 

drop table tab1 purge;
create table tab1(col1 int,col2 int,col3 varchar2(10) );

create index ind11 on tab1(col1);

insert into tab1 values(1,100,'off');
insert into tab1 values(2,100,'off');
insert into tab1 values(3,100,'off');
commit;

select * from tab1;

-- session1

select * from tab1 where col2 = 100 and col3 = 'off' order by col1 fetch first 1 rows only for update;

→ORA-02014: DISTINCT、GROUP BYなどを含むビューに対してFOR UPDATE句を使用できません

select * from tab1 where col2 = 100 and col3 = 'off' and rownum <= 1 for update;

-- session2

select * from tab1 where col2 = 100 and col3 = 'off' and rownum <= 1 for update;

→待ちになる

select * from tab1 where col2 = 100 and col3 = 'off' and rownum <= 1 for update skip locked;

→レコードが選択されませんでした。

declare
cursor cur1 is select * from tab1 where col2 = 100 and col3 = 'off' order by col1;
rtab1 tab1%rowtype;
begin
for c1 in cur1 loop
begin
select * into rtab1 from tab1 where col1 = c1.col1 for update;
update tab1 set col3 = 'on' where col1 = c1.col1 ;
commit;
exit;
exception
when no_data_found then
null;
end;
end loop;
end;
/

→待ちになる

declare
cursor cur1 is select * from tab1 where col2 = 100 and col3 = 'off' order by col1;
rtab1 tab1%rowtype;
begin
for c1 in cur1 loop
begin
select * into rtab1 from tab1 where col1 = c1.col1 for update skip locked;
update tab1 set col3 = 'on' where col1 = c1.col1 ;
commit;
exit;
exception
when no_data_found then
null;
end;
end loop;
end;
/

→col1 = 2 の行でロック取得できる

 

(11)


drop table tab1;
create table tab1(col1 int,col2 int,col3 varchar(10) );

create index ind11 on tab1(col1);

insert into tab1 values(1,100,'off');
insert into tab1 values(2,100,'off');
insert into tab1 values(3,100,'off');
select * from tab1;

-- session1
start transaction;
select * from tab1 where col2 = 100 and col3 = 'off' order by col1 limit 1 for update;

-- session2
start transaction;
select * from tab1 where col2 = 100 and col3 = 'off' order by col1 limit 1 for update;

→待ちになる

start transaction;
select * from tab1 where col2 = 100 and col3 = 'off' order by col1 limit 1 for update skip locked;

→col1 = 2 の行でロック取得できる

 

(2019)

drop table tab1;
create table tab1(col1 int,col2 int,col3 varchar(10) );

create index ind11 on tab1(col1);

insert into tab1 values(1,100,'off');
insert into tab1 values(2,100,'off');
insert into tab1 values(3,100,'off');
select * from tab1;

-- session1
begin transaction;
select top 1 * from tab1 WITH (UPDLOCK,ROWLOCK,READPAST) where col2 = 100 and col3 = 'off' order by col1;

-- session2
begin transaction;
select top 1 * from tab1 WITH (UPDLOCK,ROWLOCK) where col2 = 100 and col3 = 'off' order by col1;

→待ちになる

begin transaction;
select top 1 * from tab1 WITH (UPDLOCK,ROWLOCK,READPAST) where col2 = 100 and col3 = 'off' order by col1;

→col1 = 2 の行でロック取得できる

オーナの変更

(8.0.21)

オーナの概念なし

(12cR1)

オーナの概念なし

(9.4)

オーナーの概念あり

-- 所有権を指定してデータベース作成
create database db10 owner = user10;

-- 所有権を指定してスキーマ作成
create schema schema10 authorization user10;

-- 所有権を指定してテーブル作成
オーナを指定できない。作成したユーザがオーナとなる


-- データベースの所有権変更
alter database db10 owner to user20;

-- スキーマの所有権変更
alter schema schema10 owner to user20;

-- テーブルの所有権変更
alter table tab10 owner to user20;

 

-- あるロールによる所有される全オブジェクトの所有権変更
reassign owned by user20 to user30;


-- あるロールによる所有されるデータベース内の全オブジェクトの削除
drop owned by user30 cascade;

※ロールにより所有されるデータベースおよびテーブル空間は削除されません。

 

(2019)

オーナーの概念あり

-- 所有権を指定してデータベース作成
オーナを指定できない。作成したユーザがオーナとなる

-- 所有権を指定してスキーマ作成
create schema schema10 authorization user10;

-- 所有権を指定してテーブル作成
オーナを指定できない。所属スキーマの所有者がオーナとなる


-- データベースの所有権変更
alter authorization on database::db10 to user10;

-- スキーマの所有権変更
alter authorization on schema::schema10 to user20;

-- テーブルの所有権変更
alter authorization on object::tab1 to user20;

-- 確認
select * from sys.server_principals;
select * from sys.databases;

select * from sys.database_principals;
select * from sys.schemas;
select * from sys.tables;

 

 

タイムゾーン設定

(8.0.21)
https://qiita.com/tailak/items/63dce2dd7dfe049b038e
https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html


vim /etc/my.cnf
default-time-zone='+00:00'


select @@time_zone;
show variables like '%time_zone%';

select now();


system_time_zone: OSから引き継いだタイムゾーン
time_zone: 実際に使用するタイムゾーン

(12cR1)
https://qiita.com/tpusuke/items/c424fe771cd973d5299e
https://www.atmarkit.co.jp/ait/articles/0505/27/news116.html

原則としてOSのタイムゾーンを引き継ぐ。パラメータでの変更はできない模様


※DBTIMEZONEは「TIMESTAMP WITH LOCAL TIME ZONE型」のデータ格納時にだけ使用する
select DBTIMEZONE from dual;
alter database set time_zone='+00:00';
shutdown immediate;
startup

select systimestamp from dual;

→DBTIMEZONEを変更しても変化しない

Grid InfrastructureやSchedulerは個別の設定がある

 

(9.4)
https://qiita.com/zkangaroo/items/93be2d4504c3d1d5f185


--タイムゾーン確認
SELECT * FROM pg_timezone_names;

vim postgresql.conf
timezone = 'America/New_York'


show timezone;

select clock_timestamp();

 

(2014)

OSのタイムゾーンを引き継ぐ。パラメータでの変更はできない模様

 

シーケンス現在値確認

(8.0.21)

drop table tab1;

create table tab1 (
col1 int auto_increment,
primary key (col1)
);

insert into tab1 values();
select * from tab1;

 

analyze table tab1;

select auto_increment from information_schema.tables
where table_schema = 'test'
and table_name = 'tab1';

show table status like 'tab1'\G

※次に取得される値が表示される

(12cR1)


drop sequence seq1;
create sequence seq1 cache 20;

select seq1.nextval from dual;
select seq1.currval from dual;

select last_number from dba_sequences
where sequence_owner ='TEST'
and sequence_name='SEQ1';

select * from dba_sequences
where sequence_owner ='TEST'
and sequence_name='SEQ1';

※次に取得される値が表示される

(9.4)

drop sequence seq1;
create sequence seq1 cache 20;

select nextval('seq1');
select currval('seq1');

\x 1
select last_value from seq1;
select * from seq1;

※使用済みの最大値が表示される。

 

(2014)

drop sequence seq1;
create sequence seq1 start with 1 cache 20;


select next value for seq1;

select current_value from sys.sequences where name = 'seq1';
select * from sys.sequences where name = 'seq1';

※使用済みの最大値が表示される。