An Awk program to find all primes till N
Bug: when I run the program with argument 1, it prints 2 even though 2 > 1.

The code is not optimized at all. It computes ceil and sqrt way too often, in a way that is obvious to optimize. All other prime programs on this site already do that, have a look at them.

The code is not optimized enough. It contains i = i + 2, which should have been i += 2 from the beginning. A third of these calls can be omitted using the standard prime searching technique that has been mentioned more than enough on this site.

The variable name flag is terrible. It should be is_prime instead.

Having the most interesting code in the BEGIN block is bad design. You should define a function is_prime and another function print_primes_up_to. This allows you to declare i and j as local variables.

In the function ceil, the parameter name n is confusing since this name implies to the human reader that it is a natural number. In reality it is a floating point number though. A better name for this variable is x.

The code is missing some documentation. It should clearly state up to which number it reports correct results. It should also state the first number for which a wrong result is printed. Internally, many AWK implementations use 64-bit floating point numbers, therefore I guess this number is somewhere around \$2^{53}\$.